- Home /
Networked FindParent
How can i find the original parent of the object.
Since i have smoothfollow.cs script on the camera and the target is the player that isnt spawned yet. so the target is now set to "Point"
So i created a empty gameobject named "Point", the object is in the player and on the outside of the player.
And i need a script that finds the original "Point" gameobject so then the camera will follow the players "Point"
Answer by Sonaten · Oct 25, 2012 at 07:20 PM
Best solution is to have a variable that keeps the parent stored. Based on GameObject.Find()
JS:
var parentObject : GameObject;
function Start(){
parentObject = GameObject.Find("NameOfTheObjectAsString");
}
C#:
using UnityEngine;
using System.Collections;
public class ClassAndScriptName : MonoBehaviour {
GameObject parentObject;
void Start(){
parentObject = GameObject.Find("NameOfTheObjectAsString");
}
}
Altertively you can use the GameObject.Find during runtime. However the .Find() function can be quite heavy computationally as it checks every GameObject in the scene (which in larger project can mount to quite a bit).
I hope this can help you a bit.
Your answer
Follow this Question
Related Questions
Unity Network Spawn object and follow player 1 Answer
How to let player find an opponent online? 0 Answers
Network RPC find sender gameobject 2 Answers
How to hide a started/full server 0 Answers