Search Unity

Problem with trigger zone

Discussion in 'Scripting' started by Trild123787898, Jan 27, 2020.

  1. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    I can’t understand why I don’t want to work,
    Code (CSharp):
    1.  
    2.     public FixedJoint fxjoint;
    3.     public Rigidbody woodGrab;
    4.     void Start()
    5.     {
    6.         FixedJoint fxjoint = GetComponent<FixedJoint>();
    7.     }
    8.  
    9.     public void OnTriggerEnter(Collider other)
    10.     {
    11.         //if (other.tag == "Wood")
    12.  
    13.         fxjoint = gameObject.GetComponent<FixedJoint>();
    14.         fxjoint.connectedBody = woodGrab;
    15.                            
    16.            
    17.     }
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    What is it supposed to do? What is it doing that's wrong?
    Instead of
    gameObject.GetComponent<FixedJoint>();
    , did you meant to write
    other.gameObject.GetComponent<FixedJoint>();
    ? That's just a guess because I don't know what your code is intended to do.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    That sounds like lazyness. Might be depression. Ooooor not checking your spelling. One of those.
     
  4. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    I need so that when the object ran into vtriger then another object came close to it
     
  5. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    I just wanted to understand why it doesn’t work, in principle I already figured it out
     
  6. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    What do you mean "doesn't work"? Do you get an error message? I still haven't figured out what you wanted the code to do from your description.

    The code that you wrote will attach woodGrab to the object whenever the object touches any trigger collider. Did you want the object that has this code to be attached to the object that it collides with instead?
     
  7. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    here my mistake is that I did not watch how the trigger works