My bolt isn't respawning in game Its driving me crazy i have been at it for 2 days !!
i'm currently doing the space tutorial day 2 and i have everything but the shot spawn isn't working i've tried starting over from the start 5 times now and it still isn't working even tried changing the scripts to the done script and till doesn't work. If someone could help me it would really help thanks!!
first of all, don't post scripts as screenshots. Use the "101010" button and paste it there. Post the part related to the problem, not the whole thing. Second, be more precise on what is not working. Is the shot not appearing on screen, hence not being instantiated? Do you get errors in the console, when? Which part of the code do you reach, which not?
If you don't know what a break point is, use Debug.Log to see which parts are ran and which are not.
Answer by Dracodarkheart · Feb 04, 2017 at 05:25 AM
console
error is
ArgumentException: input button fire1 is not setup To change setting s use edit -> Input PlayerController.update() (at Assets/Scripts/PlayerController.Cs:24)
and thank i'm new to development i'm still learning this enviroment do u have write var for button input as well is that what that means?
using UnityEngine; using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
public GameObject shot;
public Transform ShotSpawn;
public float fireRate;
private float nextFire;
void Update ()
{
if (Input.GetButton("fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, ShotSpawn.position, ShotSpawn.rotation);
}
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().velocity = movement * speed;
GetComponent<Rigidbody>().position = new Vector3
(
Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
);
GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
}
}