Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class droidScript : MonoBehaviour {
- public Collider[] movementZones;
- public moveSpeed = 2;
- private zoneNum = 0;
- private Vector3 target;
- private zoneTime = 0;
- private Vector3 lastPosition;
- void Start() {
- PickTarget()
- }
- void PickTarget() {
- lastPosition = transform.position;
- Bounds zone = movementZones[zoneNum].bounds;
- float targetX = zone.min.x + zone.size.x * Random.value;
- float targetY = zone.min.y + zone.size.y * Random.value;
- float targetZ = zone.min.z + zone.size.z * Random.value;
- target = new Vector3( targetX, targetY, targetZ );
- zoneTime = 0;
- }
- void Update() {
- zoneTime += Time.time * moveSpeed;
- transform.position = Vector3.Lerp(lastPosition, target, zoneTime);
- if (zoneTime >= 1)
- {
- zoneNum++;
- if (zoneNum < movementZones.Length)
- {
- PickTarget();
- } else {
- // Destroy!!!
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment