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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

the script applies to everyone who has the script, not the individuals

Discussion in 'Scripting' started by multiplyer, Nov 2, 2015.

  1. multiplyer

    multiplyer

    Joined:
    Jan 28, 2015
    Posts:
    76
    I have a script called in the update that goes:

    Code (CSharp):
    1.  
    2. if (rbi.isKinematic == false) {
    3.  
    4. headroll.headroller = headroll.headroller + 1f;
    5. Debug.Log("Hello");
    6.  
    7. }
    it's attached to a few different objects, however, when the code is activated, through this code:

    Code (CSharp):
    1. void OnTriggerEnter (Collider other){
    2.  
    3.         if (other.tag == "proj") {
    4.  
    5.             Rigidbody rbi = gameObject.GetComponent<Rigidbody>();
    6.             rbi.isKinematic = false;
    7.  
    8. }
    it activates the first code I showed here for every object the script is on, when I would like it to only activate when that particular object is hit

    I debugged it and it registers that it hits but it turns the "isKinematic" option off for every object, when I would only like to when that particular object is hit

    Hope I explained it well enough. Any help would be great, thanks
     
  2. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    234
    Have you set the Script/Class or any of its members as static?
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    That script will only trigger if there is a trigger collision between that specific object, and an object tagged with "proj".

    This is the big problem with tags - it's hard to figure out exactly what's tagged with a tag in a scene, and forgetting to remove tags can cause major glitches.

    To debug this, try adding this to your OnTriggerEnter:

    Code (csharp):
    1. if(other.tag == "proj") {
    2.     Debug.Log("This object: " + gameObject.name + " registered a colision with this object: " + other.gameObject.name);
    3.     ...
    4. }
    That'll tell you a lot more about what collisions are happening.
     
  4. multiplyer

    multiplyer

    Joined:
    Jan 28, 2015
    Posts:
    76
    Yes. I //'d it out and tried again but still doesn't solve my problem :/

    the collision isn't the thing that's causing me the problem. the problem is that it only registers the IsKinematic becoming false once, whereas I need it to register it for every object it hits