- Home /
how to spawn object on the player C#
//need help with this Instantiate (playerdestroyEffect, Player, Quaternion.identity); //and this public GameObject Player; public GameObject playerdestroyEffect;
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playerInventory : MonoBehaviour {
public Vector3 EndPoint;
public GameObject Player;
public GameObject playercastom;
public GameObject playerparkur;
public GameObject playerparkurblue;
public GameObject playerdestroyEffect;
public void OnClick()
{
Destroy(GameObject.FindWithTag("Player"));
Instantiate (playerdestroyEffect, Player, Quaternion.identity);
Instantiate (playercastom, EndPoint, Quaternion.identity);
}
public void OnClickP()
{
Destroy(GameObject.FindWithTag("Player"));
Instantiate (playerparkur, EndPoint, Quaternion.identity);
}
public void OnClickPB()
{
Destroy(GameObject.FindWithTag("Player"));
Instantiate (playerparkurblue, EndPoint, Quaternion.identity);
}
}
Answer by CentauriDev · Dec 15, 2018 at 07:00 PM
I dont understand your question so good, but where do you assign the vector 3(Player)?
oh sorry i fix this to game object this is the old script. but i need help!
Answer by Jan-Eylander · Dec 24, 2018 at 04:17 PM
If I understand correctly you set the references to the game objects in the inspector of unity. If so you don't need to search for the player with the find object with tag stuff. And second. If you destroy the player you will lose the references to the player object inside of your script. So the instantiate call won't work means it will send a no reference found exception because the player don't exist anymore.
Your answer
Follow this Question
Related Questions
How to use tag for all players in the Instantiate. 0 Answers
Distribute terrain in zones 3 Answers
Player enable 1 Answer
How to create Prefab with property 2 Answers