Question by
CarlssonThePirate · Oct 17, 2015 at 09:17 AM ·
prefabequip
Can't use prefab on my player.
Trying to play around with unity so I made a simple player controller, and a weapon controller. I drag my Weapon Controller onto my player, and I try to assign a Prefab as the starting Gun, but for some reason it doesn't let me do it. I can't drag the Prefab to the startingGun in my script.
My weapon controller looks like this:
namespace Assets.Scripts.Weapon
{
public class WeaponController : MonoBehaviour
{
public Transform WeaponHold;
public Gun startingGun;
private Gun EquippedGun;
void Start()
{
if (startingGun != null)
{
EquipWeapon(startingGun);
}
}
public void EquipWeapon(Gun gunToEquip)
{
if (gunToEquip != null)
Destroy(EquippedGun.gameObject);
EquippedGun = Instantiate(gunToEquip, WeaponHold.position, WeaponHold.rotation) as Gun;
if (EquippedGun != null)
EquippedGun.transform.parent = WeaponHold;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Editor script: Variable created on gameObject in editor set to missing on runtime 0 Answers
the tree couldn't be instanced because the prefab contains no valid mesh renderer 0 Answers
Player trigger on platform with prefab 0 Answers
Separation of prefab model parts 0 Answers
How to creating a Gameobject from a prefab via scripted UI BUTTON 1 Answer