Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Collider Problems

Discussion in 'Scripting' started by Gip-Gip, Jul 8, 2014.

  1. Gip-Gip

    Gip-Gip

    Joined:
    Mar 9, 2014
    Posts:
    4
    I am trying to add a drinking mechanic to my game but I have yet to get it to work:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Drinking : MonoBehaviour {
    5.     public int thirst = 50;
    6.  
    7.     void OnTriggerStay(Collider other)
    8.     {
    9.         if (other.gameObject.tag == "Drink" && thirst < 100 && Input.GetKeyDown("e"))
    10.                         thirst = thirst + 25;
    11.     }
    12.  
    13. }
    Anyone know what I might be doing wrong?

    EDIT:
    I got it to work. All I had to do was expand the trigger around the player.:oops:
     
    Last edited: Jul 8, 2014
  2. Aishiteru

    Aishiteru

    Joined:
    May 3, 2014
    Posts:
    31
    If the game object does not have rigid body I think ontrigger method won't be called
     
  3. Gip-Gip

    Gip-Gip

    Joined:
    Mar 9, 2014
    Posts:
    4
    A cup, which is the object i'm using, does have a rigidbody attached. But thanks anyways!