- Home /
Question by
Rocka_the_Shocka · Jun 14, 2018 at 08:08 AM ·
c#beginnershooting
Need Help fixing shooting script in c#
I am a beginner to coding in general and could use some tips to help with fixing this script. I have tried many ideas but keep getting error after error.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class shootar : MonoBehaviour {
void Start(
)
{Update
Input.GetMouseButtonDown("Fire1");
Instantiate(Bullet);
GameObject BulletClone = Instantiate(Bullet, transform.position, transform.rotation);
BulletClone.GetComponent<Rigidbody>().velocity = BulletClone.transform.forward;
}
}
Comment
Best Answer
Answer by MT369MT · Jun 14, 2018 at 04:10 PM
You should store your instantiated object in a variable, try something like this.
GameObject BulletClone = Instantiate(Bullet, transform.position, transform.rotation);
BulletClone.GetComponent<Rigidbody>().velocity = BulletClone.transform.forward;
Remember to add a Rigidbody to your BulletPrefab
Thanks now i just have to fix any tiny errors now