Search Unity

[resolved] Communicate Transform position between two objects

Discussion in 'Scripting' started by bchevriaut, Dec 22, 2014.

  1. bchevriaut

    bchevriaut

    Joined:
    Nov 17, 2014
    Posts:
    2
    Hi,

    I currently have two classes : Character and zombie.
    I would like to give to my zombie my character position.

    This is my character class :
    public class Character : MonoBehaviour{

    public Transform GetMyPosition(){
    return this.transform;
    }

    }

    And there is my zombie class :
    public class zombie : MonoBehaviour {

    public Transform origin;
    public Character character;

    void Update () {
    deplace ();
    }
    void deplace(){
    //Vector3 destination = cible.position;
    Vector3 alienPos = origin.position;

    origin.LookAt (character.GetMyPosition());

    }
    }

    Problem is that actually, zombies are looking at 0.0.0 : my original position, and they keep looking at 0.0.0 when i am mooving.

    This is how i linked ressources :



    Thank you for your help !
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    You just need the Characters position from the zombie script?

    Use

    Private Transform _player;

    void Start()
    {
    _player = GameObject.Find("Player").GetComponent<Transform>();
    }

    To get the position of the player: _player.position
     
    bchevriaut likes this.
  3. bchevriaut

    bchevriaut

    Joined:
    Nov 17, 2014
    Posts:
    2
    Great, that works !
    Thank you :)
     
    SubZeroGaming likes this.