Hello everyone.
Currently I have a script Which fires projectiles That works well in 3D.
I need help to change it in 2d shot. I added Rigidbody2D. By testing the script works, but the shot does not travel on the axis x or -x. the shot explodes in front of the character in 2D without traveling on the axis X.
How can you change this script from 3d to 2d shot?
#pragma strict
var Prefab : Transform;
var PrefabSpeed : float = 6000;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
if(Collisions.GRENADE_AMMO > 0)
if(!Prefab || !PrefabSpeed)
{
Debug.Log("Il prefab o la velocità non esiste");
}
else
{
var PrefabCreate = Instantiate(Prefab,GameObject.Find("Projectile Spawn").transform.position,Quaternion.identity);
PrefabCreate.rigidbody2D.AddForce(transform.forward * PrefabSpeed);
Collisions.GRENADE_AMMO --;
GameObject.Find("g_Count").guiText.text = ""+Collisions.GRENADE_AMMO;
print("YOU NOW HAVE " + Collisions.GRENADE_AMMO + " GRENADES");
}
}
}