How to “call” a prefab in script

Updated on December 19, 2015 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on December 19, 2015

Hi everyone,

I am trying to spawn bullets where my gun is with the aim of later making my gun shoot. However, I am having trouble to “call”, or refer to, the bullet prefab in order to later use it in the instantiate function. The following script is for the 2D, top-down view, survival shooter and it is applied to my gun. Any help, please?

using UnityEngine;
using System.Collections;

public class Shooting : MonoBehaviour {

GameObject LaBe = GameObject.Find(“LaserBeam”);

void Update () {
if (Input.GetKeyDown (KeyCode.Mouse0)) {
Instantiate(LaBe, transform.position, transform.rotation);
}
}
}

Thx in advance!

  • Liked by
Reply
0 on December 19, 2015

Alright yeah I’ll do tht, thx!

  • Liked by
Reply
Cancel