Created
December 12, 2015 23:38
-
-
Save rondagdag/02968b2c6cacdaf76805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class DinoController : MonoBehaviour { | |
GameObject player; | |
// Use this for initialization | |
Vector3 initialPosition; | |
public float speed = 0.1F; | |
public AnimationClip idleAnimation01 ; | |
public AnimationClip idleAnimation02 ; | |
public AnimationClip idleAnimation03 ; | |
public AnimationClip jump ; | |
int idleRnd; | |
private Animation _animation; | |
public bool isJumping; | |
void Start () { | |
player = GameObject.FindGameObjectWithTag ("Player"); | |
initialPosition = transform.position; | |
gameController = GameObject.FindGameObjectWithTag ("GameController"); | |
littlebitsData = gameController.GetComponent<LittlebitsWSDino> (); | |
} | |
GameObject gameController; | |
LittlebitsWSDino littlebitsData; | |
float minValue = 0.1f; | |
float maxValue = 0.2f; | |
public float growthSpeed = 0.5F; | |
float scaleValue; | |
Vector3 vector; | |
void Awake () | |
{ | |
//moveDirection = transform.TransformDirection (Vector3.forward); | |
_animation = GetComponent<Animation>(); | |
} | |
// Update is called once per frame | |
void Update () { | |
scaleValue = (minValue + littlebitsData.value * 0.001f); | |
Debug.Log ("Value: " + scaleValue); | |
if (littlebitsData.value > 80) | |
isJumping = true; | |
else | |
isJumping = false; | |
vector = new Vector3(scaleValue,scaleValue,-scaleValue); | |
transform.localScale = Vector3.Lerp (transform.localScale, vector, growthSpeed * Time.deltaTime); | |
if (player.activeInHierarchy) { | |
transform.LookAt (player.transform); | |
//Debug.Log (player.transform.position.y); | |
//float newPositionY = Mathf.Lerp (transform.position.y, player.transform.position.y, Time.deltaTime); | |
//transform.position = new Vector3 (initialPosition.x, newPositionY, initialPosition.z); | |
vector = new Vector3 (initialPosition.x, player.transform.position.y, initialPosition.z); | |
transform.position = Vector3.Lerp(transform.position, vector,Time.deltaTime); | |
} else { | |
transform.position = initialPosition; | |
} | |
if (isJumping) { | |
_animation.CrossFade (jump.name); | |
} else { | |
idleRnd = Random.Range (0, 3); | |
//Debug.Log (idleRnd); | |
switch (idleRnd) { | |
case 0: | |
_animation.CrossFade (idleAnimation01.name); | |
break; | |
case 1: | |
_animation.CrossFade (idleAnimation02.name); | |
break; | |
case 2: | |
_animation.CrossFade (idleAnimation03.name); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment