Menu
CoddyTech

打进球洞

本课属于 Coddy Unity 学习旅程的“物理与游戏玩法”单元。第 69 课,共 71 课。

challenge icon

挑战

困难

让一颗慢速弹珠落入球洞。

  1. 在 Hole 中,添加 void OnTriggerEnter(Collider other)。
  2. 当 other.TryGetComponent(out Golf golf) 和 other.attachedRigidbody.linearVelocity.magnitude < sinkSpeed 满足时,记录 "In the cup in " + golf.strokes + " strokes!",并调用 other.gameObject.SetActive(false);。

按下“开始”,让弹珠入洞:快速弹珠会滚过球洞。然后点击“检查”。

亲手试试

using UnityEngine;

public class Hole : MonoBehaviour
{
    [SerializeField] private float sinkSpeed = 3f;

    // 弹珠滚得慢就会掉进杯子,滚得快就会滚过去。
}

物理与游戏玩法中的所有课

自己练习: Unity 在线编辑器