public class fishGame : MonoBehaviour {
enum FishDir //设置朝向的枚举
{
left,
right
}
FishDir dir; //申明一个方向控制鱼
// Use this for initialization
void Start () {
float random = Random.value; //随机设置鱼的方向
while (random==0.5f) //循环判断random直到整个数字不等于0.5
{
random = Random.value;
}
if (random>0.5f) //如果随机数大于0.5的情况和小于的情况
{
dir = FishDir.left;
}
else
{
dir = FishDir.right;
}
ChangeDir(); //调用改变方向的方法
}
// Update is called once per frame
void Update () {
}
void ChangeDir()
{
Vector3 scale = transform.localScale; //设置scale变量
if (dir == FishDir.left) //判断如果鱼儿的方向朝左时设置鱼儿的scale=1
{
scale.x = 1;
}
else
{
scale.x = -1;
}
transform.localScale = scale; //重新赋值
}
}