Advertisement
infinite_ammo

Moon.cs

Apr 4th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Moon : StateMachine<Moon.State>
  5. {
  6.     public enum State
  7.     {
  8.         Idle,
  9.         Move,
  10.         Max
  11.     }
  12.  
  13.     public float moveForce = 1.0f;
  14.     public Transform model;
  15.     public float velocityLookMultiplier = 0.1f;
  16.     public float lookForward = 0.5f;
  17.  
  18.     public GameObject leftEye;
  19.     public GameObject rightEye;
  20.  
  21.     public float minBlinkTime = 0.5f;
  22.     public float maxBlinkTime = 2.0f;
  23.     public float blinkDuration = 0.125f;
  24.  
  25.     void Awake()
  26.     {
  27.         Blink();
  28.     }
  29.  
  30.     void Blink()
  31.     {
  32.         leftEye.SetActiveRecursively(false);
  33.         rightEye.SetActiveRecursively(false);
  34.  
  35.         Invoke("UnBlink", blinkDuration);
  36.     }
  37.  
  38.     void UnBlink()
  39.     {
  40.         leftEye.SetActiveRecursively(true);
  41.         rightEye.SetActiveRecursively(true);
  42.        
  43.         Invoke("Blink", Random.Range(minBlinkTime, maxBlinkTime));
  44.     }
  45.  
  46.     void Update()
  47.     {
  48.         UpdateMovement();
  49.     }
  50.  
  51.     void UpdateMovement()
  52.     {
  53.         Vector3 move = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0.0f);
  54.         rigidbody.AddForce(move * moveForce * Time.deltaTime);
  55.  
  56.         transform.forward = -rigidbody.velocity * velocityLookMultiplier * (1.0f - lookForward) + Vector3.forward * lookForward;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement