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. Dismiss Notice

Broadcasting a game objects position so other game objects can position themselves accordingly

Discussion in 'General Discussion' started by Genkidevelopment, Jan 15, 2015.

  1. Genkidevelopment

    Genkidevelopment

    Joined:
    Jan 2, 2015
    Posts:
    186
    I have an equation which I am scripting onto GameObjectB...

    Part of this equation is GameObjectB's position... What is the easiest way of subbing these coordinates into the script...

    The following script is assigned to GameObjectB... it is intended to transform the position of GameObjectB along the z axis relative to the position of GameObjectA and a futher variable named MyFloat...

    1 using UnityEngine;
    2 using System.Collections;
    3
    4 public class GameObjectBPositionScript : MonoBehaviour {
    5 float MyFloat = 2.5;
    6
    7 // Update is called once per frame
    8 void Update () {
    9 transform.Translate ( 0f, 0f, GameObject A's Position / MyFloat );
    10 }
    11 }

    I need to be doing this for two dozen other game objects at the same time also...

    Many thanks Unity'ers :D
     
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  3. Genkidevelopment

    Genkidevelopment

    Joined:
    Jan 2, 2015
    Posts:
    186
    Thanks you very much... Simply getting to the right tutorial is half of my problem... Although gradually I am coming to terms with the concepts and terminology, helps a lot :D