69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class Snailmove : MonoBehaviour
|
|||
|
{
|
|||
|
private float moveTimer = 0f; // <20><>ʱ<EFBFBD><CAB1>
|
|||
|
private float moveSpeed = 10f; // <20>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
|
|||
|
public Vector3 moveDirection; // <20><>ǰ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public Animator animator; // Animator<6F><72><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
private bool isMoving = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|||
|
public long id;
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
|
|||
|
moveDirection=Vector3.right;
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
// ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
moveTimer += Time.deltaTime;
|
|||
|
|
|||
|
// ÿ3<C3BF><33><EFBFBD>ı<EFBFBD>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD>
|
|||
|
if (moveTimer >= 10f)
|
|||
|
{
|
|||
|
ChangeDirection();
|
|||
|
moveTimer = 0f;
|
|||
|
}
|
|||
|
|
|||
|
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
transform.Translate(moveDirection * moveSpeed * Time.deltaTime);
|
|||
|
if (transform.localPosition.x <= -600 || transform.localPosition.x >= 600)
|
|||
|
{
|
|||
|
transform.localPosition = new Vector3(0, transform.localPosition.y, transform.localPosition.z);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private void ChangeDirection()
|
|||
|
{
|
|||
|
|
|||
|
int randomDirection = Random.Range(0, 3);
|
|||
|
if (randomDirection <= 1)
|
|||
|
{
|
|||
|
moveDirection = Vector3.right;
|
|||
|
transform.rotation = Quaternion.Euler(0, 0, 0);
|
|||
|
animator.SetBool("move",true);
|
|||
|
}
|
|||
|
if(randomDirection <= 2&& randomDirection > 1)
|
|||
|
{
|
|||
|
moveDirection = Vector3.right;
|
|||
|
transform.rotation = Quaternion.Euler(0, 180, 0);
|
|||
|
animator.SetBool("move", true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
moveDirection = Vector3.zero;
|
|||
|
animator.SetBool("move", false);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|