- Home /
Question by
JamesBrodski · Jun 10, 2016 at 12:09 PM ·
c#unity 5fpsdestroy objectaiming
How to delete prefabs without warning popping up?
I'm trying to make a very very basic fps game where the player can walk around, point, and un-point his gun, and shoot stuff. The way im trying to do it, I spawn a picture of an unaimed gun in void Start(). Then, if the player presses on the left button of the mouse, I wan't to delete the old picture and replace it with the guy aiming the gun. Here is my code.
using UnityEngine;
using System.Collections;
public class GunAim : MonoBehaviour {
public GameObject NotAiming;
public GameObject Aiming;
public float yPos = -2.15f;
// Use this for initialization
void Start ()
{
Instantiate(NotAiming, new Vector3(0, yPos, 0), Quaternion.identity);
}
void Update() {
if(Input.GetKeyDown(KeyCode.Mouse0))
{
Instantiate(Aiming, new Vector3(0, yPos, 0), Quaternion.identity);
Destroy(NotAiming);
}
}
}
Problem is, I get an error when I try to destroy a prefab.
Comment