Question by
okaybj · Nov 20, 2019 at 12:37 AM ·
scripting problemprefab
How do I reference the player within an instantiated prefab?
I'm trying to make an instantiated prefab get bigger when the player gets closer to it. I'm using this method:
void Start()
{
player = Object.FindObjectOfType<player>();
}
public void Update () {
if (Vector3.Distance(player.transform.position, PREFAB1) < PLAYER_DISTANCE) {
GetBig();
}
}
public void GetBig() {
Debug.Log("got bigger");
}
The player class is made here in a player manager script on an empty game object in the scene like so:
public player player;
public static playerManager Instance { get; private set; }
void Awake() {
if (Instance == null) { Instance = this; }
else { Destroy(gameObject); }
player = FindObjectOfType<player>();
}
Why doesn't it work? :(
Comment
Your answer
Follow this Question
Related Questions
Mesh missing in prefab 0 Answers
Variables in a script on a prefab do not store runtime changes 0 Answers
How to Create variants with different scripts interact with player 1 Answer
Why does Unity lock the transform of prefabs in my scene in playmode? 0 Answers
Showing a high score in the menu 1 Answer