コード例 #1
0
    public void OnTriggerEnter(Collider other)
    {
        IHealth health;

        if (other.tag == "Player")
        {
            health = other.GetComponent <IHealth>();
            if (health == null)
            {
                Debug.LogError("object tagged 'Player' doesn't have IHealth; " + other.name);
            }
            else
            {
                health.TakeDamage(_damage);
                Destructor();
            }
        }
        if (other.tag == "Enemy")
        {
            DonutController donut = other.GetComponent <DonutController>();
            if (donut != null)
            {
                health = other.GetComponent <IHealth>();
                if (health == null)
                {
                    Debug.LogError("object with donut controller doesn't have IHealth; " + other.name);
                }
                else
                {
                    health.AddHealth(1);
                    Destructor();
                }
            }
        }
    }
コード例 #2
0
 // Use this for initialization
 void Start()
 {
     coffee          = GameObject.FindGameObjectWithTag("Coffee");
     donut           = GameObject.FindGameObjectWithTag("Donut");
     cigarette       = GameObject.FindGameObjectWithTag("Cigarette");
     donutController = donut.GetComponent <DonutController>();
     head            = GetComponent <SphereCollider>();
     StartCoroutine(activateCollider());
 }