Unity3d 碰撞处理

void OnTriggerEnter(Collider other) 
{
   if(other.tag.Compare("PlayerRocket") == 0) 
  {
      Rocket rocket = other.GetComponent<Rocket>();
      if(rocket != null) 
      {
         m_life -= rocket.m_power;
       
         if(m_life <= 0) 
         {
             Destory(this.gameObject);
         }
         else if(other.tag.CompareTo("player") == 0) 
        {
             m_life = 0;
             Destory(this.gameObject);
         }
      }
   }
}

void OnTriggerEnter(Collider other)

设置tag  和 Collider

other.tag.CompareTo(TagName);

对比tag 

 

posted on 2013-12-10 23:07  DAWN09151111  阅读(356)  评论(0)    收藏  举报

导航