This question was
closed Apr 22, 2016 at 09:07 PM by
Alexander42 for the following reason:
The question is answered, right answer was accepted
Question by
Alexander42 · Apr 22, 2016 at 06:55 PM ·
2dinstantiateprefabinput
Trying to get a 2d prefab without rigidbody to instantiate on button press, "the variable T_Bullet has not been assigned."
Full Code:
using UnityEngine;
using System.Collections;
public class player_script : MonoBehaviour {
public float speed = 8f;
public float countdown = 3.0f;
private bool m_Fired;
public GameObject T_Bullet;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1"))
{ transform.Translate(Vector2.up * Time.deltaTime ); }
if (Input.GetButton("Fire2"))
{ transform.Translate(Vector2.down * Time.deltaTime ); }
if (Input.GetButton("Jump"))
{ Fire(); }
}
private void Fire()
{
Instantiate(T_Bullet,Vector2.right, Quaternion.identity);
}
}
Trying to get a bullet prefab to spawn when the spacebar is pressed, but the Console gives me that error message. Most of the other answers for this topic involve 2d Rigidbodies, which I have no reason to use for the sort of game I am making
Comment
I believe you have already added the prefab into the inspector, why not add a kinematic rigidbody2D? It won't have gravity or be affected by any forces