using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public Transform firePoint;
public GameObject bullet;
public float bulletForce = 20f;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
Instantiate(bullet, firePoint.position, firePoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * bulletForce * Time.deltaTime, ForceMode2D.Impulse);
}
}
You aren’t calling rb.AddForce
on the bullet that you instantiated, but you are instead calling it on the public GameObject bullet;
reference in the script…
To make it work again just change your script to :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public Transform firePoint;
public GameObject bullet;
public float bulletForce = 20f;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
GameObject Bullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
Rigidbody2D rb = Bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * bulletForce * Time.deltaTime, ForceMode2D.Impulse);
}
}