ボールの作成

Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ball : MonoBehaviour
{

    public float speed = 1.0f;
    private Rigidbody myRigit;
    public gameManager myManager;
    public static int score;

    // Start is called before the first frame update
    void Start()
    {
        myRigit = this.GetComponent<Rigidbody>();
        myRigit.AddForce((transform.forward + transform.right) * speed, ForceMode.VelocityChange);
        score = 0;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "block")
        {
            myManager.setScore(10);
        }

        if ( collision.gameObject.tag == "Finish")
        {
            Destroy(this.gameObject);
            myManager.GameOver();
        }
    }
}

コメント

タイトルとURLをコピーしました