2020-03-08

ぃ、小莉子 提交于 2020-03-09 06:44:21

贪吃蛇食物生成

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++;
}
}
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!