Пример #1
0
    public void OnTriggerEnter(Collider other)
    {
        /*引数として受け取るotherはこの場合は壁
         * GoalManager goalManager = other.gameObject.GetComponent<GoalManager>();
         *↑GoalManager型のgoalManager変数にGetComponentでGoalManagerを取得して代入
         * GoalManager型のgoalManager変数からGoalManagerクラスのメソッドを呼び出し可能
         */


        if (other.gameObject.tag == "Wall")
        {
            GoalManager goalManager = other.gameObject.GetComponent <GoalManager>();
            goalManager.PlaySound();
            FindObjectOfType <ScoreManager>().AddScore(-10);
        }
    }