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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Issue Setting one object to be at the same position as another

Discussion in 'Scripting' started by JetpackJoker, Mar 11, 2018.

  1. JetpackJoker

    JetpackJoker

    Joined:
    Dec 19, 2017
    Posts:
    4
    I'm sure I am making a simple mistake but here is my script.
    Code (CSharp):
    1. public class CapsuleControl : MonoBehaviour {
    2.     GameObject obj1;
    3.     GameObject obj2;
    4.  
    5.     // Use this for initialization
    6.     void Start () {
    7.         obj1=GameObject.Find("Player");
    8.         obj1=GameObject.Find("PlayerSnowboardAssembly");
    9.  
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.  
    15.         obj1.transform.position=obj2.transform.position;
    16.  
    17.     }
    18. }
    I am only referencing parents here yet the "Player" object is not moving. My only guess is that the second object "PlayerSnowboardAssembly" has a rigidbody attached.
     
  2. Pagefile

    Pagefile

    Joined:
    Feb 10, 2013
    Posts:
    51
    You're assigning obj1 twice, so it ends up being the snowboard assembly instead of the player
     
  3. JetpackJoker

    JetpackJoker

    Joined:
    Dec 19, 2017
    Posts:
    4
    Thank you I am actually blind
     
  4. Pagefile

    Pagefile

    Joined:
    Feb 10, 2013
    Posts:
    51
    No worries. I miss things like that too sometimes and wonder how I even made it out of bed.