代码:https://gitee.com/cmd_develop/unity_ball_roll
1.text 文字更改
public Text text;
text.text = "成绩:" + score.ToString();
2.节点的显示与隐藏
public GameObject win_text;
win_text.SetActive(true);
win_text.SetActive(false);
3.节点的删除
void OnTriggerEnter(Collider other)
{
Destroy(other.gameObject);
}
4.触发检测(只触发不碰撞)
void OnTriggerEnter(Collider other)
{
if(other.tag == "food"){xxx}
}
image.png
5.碰撞检测,注意把第四点的触发器给关闭
1.png
6.相机跟随
void Start()
{
offset = transform.position - ball.position;
}
// Update is called once per frame
void Update()
{
transform.position = ball.position + offset;
}
7.物品旋转
transform.Rotate(new Vector3(0,1,0));
网友评论