The problem is that the player can't fire. After i press (1) and try to fire nothing happened. I am trying to make a script that when i press button (1) to shoot with weapon 1 and pressing (2) to shoot with weapon 2.
var rotatespeed : float = 3.0f ;
var BulletPrefab : Transform ;
var BulletPrefab1 : Transform ;
function Update () {
// Mouse controll
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if(playerPlane.Raycast (ray, hitdist))
{
var targetPoint = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotatespeed * Time.deltaTime);
}
// Bullet Spawn
if(Input.GetKeyDown("1"))
{
var weapon1 = 1 ;
Debug.Log("press 1") ;
if(Input.GetButtonDown("Fire1") && weapon1 == 1) {
var bullet = Instantiate(BulletPrefab, GameObject.Find("bulletspawn").transform.position, transform.rotation );
bullet.rigidbody.AddForce(transform.forward * 1000) ;
Debug.Log("Fire weapon 1") ;
}
}
if(Input.GetKeyDown("2"))
{
var weapon2 = 2 ;
Debug.Log("press 2") ;
if(Input.GetButtonDown("Fire1") && weapon2 == 2)
{
var bullet1 = Instantiate(BulletPrefab1, GameObject.Find("bulletspawn").transform.position, transform.rotation );
bullet.rigidbody.AddForce(transform.forward * 1000) ;
Debug.Log("Fire weapon 2") ;
}
}
}