Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
well , i'm new in unity and still learning i want to ask about code of how to update object the movement of another object and make them move together ??
Posted

 
Share this answer
 
v2
Comments
Hussien Ezzat 15-Apr-14 12:45pm    
i have been used this code to make object 1 having the same position of object 2 and didn't work
GameObject.Find("object1").transform.position = new Vector3(GameObject.Find("object2").transform.position.x,GameObject.Find("object2").transform.position.y,GameObject.Find("object2").transform.position.z);
Attach this script to object1.

C#
using UnityEngine;
using System.Collections;


public class Follow: MonoBehaviour {
    GameObject TargetObject;

	void Start () {
        TargetObject = GameObject.Find("object2");
        }
	
	void FixedUpdate () {
        this.transform.position = TargetObject.position;
        }
}


this gives the exact same position on object1 as object2.This is no good if you want a smooth follow.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900