Can anyone please help me, i dont understand what the problem is here. The Thread name is the error i keep getting in console. I will appreciate anyones help ❤️
Players Script --- ```public class PlayerController : MonoBehaviour
{
public float playerSpeed;
private Rigidbody playerRb;
public BulletScript bulletScript;
void Start()
{
playerRb = GetComponent<Rigidbody>();
bulletScript = GameObject.Find("Bullet").GetComponent<BulletScript>();
}
void Update()
{
//Move Player Vertical And Horizontal
float forwardInput = Input.GetAxis("Vertical");
float sidewaysInput = Input.GetAxis("Horizontal");
playerRb.AddForce(Vector3.forward * forwardInput * playerSpeed);
playerRb.AddForce(Vector3.right* sidewaysInput * playerSpeed);
// If Mouse Left is Clicked, call function from BulletScript
if (Input.GetButtonDown("Fire1"))
{
bulletScript.Shoot();
}
}
} ```
Bullet Script ---
{
private Rigidbody bulletRb;
private GameObject player;
public GameObject bulletPrefab;
private float bulletVelocity = 5;
// Start is called before the first frame update
void Start()
{
bulletRb= GetComponent<Rigidbody>();
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
}
public void Shoot()
{
Vector3 playerPos = player.transform.position;
Instantiate(bulletPrefab, playerPos, bulletRb.transform.rotation);
Debug.Log("YOU SHOT!");
}
} ```