unity3D__主角打怪物

来源:互联网 发布:苹果铃声截取软件 编辑:程序博客网 时间:2024/05/17 07:58

欢迎大家关注我的日志,今天简单的讲讲主角打怪物:

 

//主角走动


private NavMeshAgent agent;
public GameObject hero;
public static float lifeTime = 0f;
public bool flag=false ;
//private float timer=1f;
void Start () {
agent =GetComponent <NavMeshAgent >();
}

// Update is called once per frame
void Update () {
if(Input .GetMouseButtonDown (0)){
Ray ray=Camera .main .ScreenPointToRay (Input .mousePosition );
RaycastHit hitInfo;
if (Physics .Raycast (ray ,out hitInfo )){
agent .SetDestination (hitInfo .point);
}
}


//调用主角的方法,实现主角的各种动作


if (flag) {
work ();
//timer -= Time .deltaTime;
//if (timer <= 0) 
// {
//print ("AAAAAAAAA");
flag = false;
//timer = 1f;
//}

else 
{
if (agent .remainingDistance == 0) 
{
idle ();

else 
{
walk ();
}
}
}
void idle(){
hero .transform .animation .Play ("idle");
}
void walk(){
hero .transform .animation .Play ("walk");
}
void work(){
hero .transform .animation .Play ("idle to working");
}


//实现碰撞效果,使主角攻击怪物


void OnTriggerEnter(Collider other){
if (other.CompareTag("a"))
{

flag = true;
}
}
}


//给主角武器加碰撞


int life=2;//怪物生命值为2
void Start () {

}

void OnTriggerEnter(Collider other) {
if (other.CompareTag("b"))
{
life --;
if (life ==0){
Destroy(this .gameObject);
}
}
}

如果大家还有什么困难的话可以关注我的日志:

http://unity.gopedu.com/home.php?mod=space&do=blog&view=me

 

还可以关注我们的狗刨网:

http://unity.gopedu.com


0 0
原创粉丝点击