Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Add 2 conditions to disable an object. (Trigger+MouseClick) how ?

Discussion in 'Scripting' started by staincorb, Aug 8, 2014.

  1. staincorb

    staincorb

    Joined:
    Mar 30, 2009
    Posts:
    123
    var ObjectsToApear : GameObject;

    function OnTriggerEnter (Other : Collider){
    if(Other.gameObject.tag == "PlayerEyes"){
    ( Input.GetButtonDown("Fire1") );


    ObjectsToApear.active = false;
    }
    }


    Hi all.

    I have an object that is linked to the camera, that is a riggid body and Kinematic, so that I can use that object to collide on triggers, instead of the FirstPersonController, now this lets me use an object like eyes, With this method, its posible to interact with object only if your looking at em.

    Now the problem is in my scripting ability, wich is Null.

    I need the above script to be able to deactivate the object when I am coliding with trigger and LeftClick but it disables when my Eyes object collides with trigger imediatelly.

    What do I write in script to say this.

    If object (PlayerEyes) is colliding and pres (Fire1)
    Disable Object ?

    I hope I dont have to use booleans, couse imediatelly f I type in Bool or Boolean, it tells me it dosent know what that is, and neather Do I, So I hope to evade them for now.

    Thx for any help.
     
  2. Arghonaut

    Arghonaut

    Joined:
    Jul 23, 2012
    Posts:
    26
    From what it sounds like you just need to use &&, and OnTriggerStay would be more appropriate. Also, use code tags:

    Code (csharp):
    1.  
    2. function OnTriggerStay (Other : Collider){
    3.     if(Other.gameObject.tag == "PlayerEyes" && Input.GetButtonDown("Fire1")){
    4.  
    5.     ObjectsToApear.active = false;
    6.     }
    7. }
    8.  
    But in all honesty, if you don't understand bools and the && operator, spend an evening doing some tutorials, they are really basic stuff.
     
  3. staincorb

    staincorb

    Joined:
    Mar 30, 2009
    Posts:
    123
    Thx for the reply,

    The script dosent do anything any more, so I will just try another method. where I can separate the two lines of script into two diferent objects, at least I have an ideah on how to use &&, and I apreciate the help a lot.

    Thx