using UnityEngine;
using System.Collections;
[RequireComponent (typeof(AudioSource))] //i don't need to Input Audio sources again in component.
public class MonsterCtrl : MonoBehaviour {
public Transform PlayerTr;
public Transform MonsterTr;
public NavMeshAgent nv;
public float TraceTime = 0.5f;
public Animator anim;
// Use this for initialization
void Start () {
PlayerTr = GameObject.Find ("Player").GetComponent<Transform>();
MonsterTr = this.gameObject.GetComponent<Transform>();
nv = GetComponent<NavMeshAgent>();
nv.destination = PlayerTr.position; //start to trace where player's position.
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Vector3.Distance(MonsterTr.position,PlayerTr.position) < 2.0f)
{
nv.Stop();//stop trace~!!!!
anim.SetBool("IsAttack",true);
anim.SetBool("IsTrace",false);
}else
{
if(Time.time > TraceTime)
{
nv.destination = PlayerTr.position;
TraceTime = Time.time + 0.5f;
}
nv.Resume(); //restart to trace~!!!!
anim.SetBool("IsAttack",false);
anim.SetBool("IsTrace",true);
}
}
}
'유니티3D > 예제' 카테고리의 다른 글
시계바 (0) | 2013.08.20 |
---|---|
PaddleGame (0) | 2013.08.15 |
메카님방식 (0) | 2013.08.12 |
BulletCtrl.cs (0) | 2013.08.07 |
miniMap (0) | 2013.08.07 |