I was trying to learn unity by following space shooter tutorial. All was good until I tried to test my game to shoot lasers. I followed everything but shots are not firing with fire button. And when I removed the if condition to get continuous shots, it's not happening also. Here's my player controller script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Boundary{
public float xMin,xMax,zMin,zMax;
}
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody player;
public Boundary boundary;
public float tilt,fireRate;
public GameObject shot;
private float nextFire;
public Transform showSpawn;
void Start(){
player = GetComponent<Rigidbody>();
}
void update(){
//if (Input.GetButton ("Fire1") && Time.time > nextFire) {
//nextFire = Time.time + fireRate;
Instantiate (shot,showSpawn.position,showSpawn.rotation);
//}
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
player.velocity = movement * speed;
player.position = new Vector3 (
Mathf.Clamp(player.position.x,boundary.xMin,boundary.xMax),
0.0f,
Mathf.Clamp(player.position.z,boundary.zMin,boundary.zMax)
);
player.rotation = Quaternion.Euler(0.0f,0.0f,player.velocity.x*-tilt);
}
}
And here's mover script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour {
public float speed;
private Rigidbody bolt;
// Use this for initialization
void Start () {
bolt = GetComponent<Rigidbody>();
bolt.velocity = transform.forward * speed;
}
}
Here's the direct link to the part of tutorial
P.S I'm using Unity 5