贪吃蛇食物生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour {
// Use this for initialization
private int score = 0;
void Start () {
transform.position =new
Vector3(Random.Range(-9, 9), 1, Random.Range(-9, 9)); //食物随机出生
}
// Update is called once per frame
void Update () {
transform.Rotate(0,-1,1);
//食物旋转
}
void OnTriggerEnter(Collider collider)
{
if (collider.name == “Ball”)
{
if (score < 14){ transform.position = new Vector3(Random.Range(-9, 9), 1,Random.Range(-9, 9)); } //重新生成食物
else{
Destroy(gameObject);
} //删除食物score++;
}
}
}
来源:CSDN
作者:weixin_46485624
链接:https://blog.csdn.net/weixin_46485624/article/details/104737146