Skip to content

Instantly share code, notes, and snippets.

@peroon
Created June 6, 2016 11:39
Show Gist options
  • Select an option

  • Save peroon/fbc24225b6c54972a374855d2ec478e6 to your computer and use it in GitHub Desktop.

Select an option

Save peroon/fbc24225b6c54972a374855d2ec478e6 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using DG.Tweening;
// 逃げる子猫
public class Kitten : MonoBehaviour {
private Animator animator;
public float runDuration = 1.0f;
public float runSpeed = 10.0f;
public float runTime = 3.0f;
private float time;
private bool isRun = false;
private Vector3 runDirection; // 走る方向
void Start () {
animator = this.GetComponent<Animator> ();
}
void Update () {
if (isRun) {
transform.Translate (runSpeed * runDirection * Time.deltaTime, Space.World);
runTime -= Time.deltaTime;
if (runTime < 0.0f) {
isRun = false;
animator.SetTrigger("triggerIdol");
}
}
}
// カメラが近づくと逃げる
void OnTriggerEnter(Collider other) {
if (other.tag == TagConst.MainCamera) {
SoundManager.Instance.PlayVoice (VOICE.MEOW);
// 逃げアニメ
animator.SetTrigger("triggerRun");
// 逃げる方向
runDirection = (this.transform.position - other.transform.position).normalized;
Debug.Log (this.transform.position);
Debug.Log (other.transform.position);
runDirection.y = 0.0f;
isRun = true;
time = runTime;
// 逃げる方向を向く
this.transform.DOLookAt(this.transform.position + runDirection, 0.5f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment