Hi everyone, stupid me accidently deleted my script and I had to write it again and now there are problems. If someone could help me it would be much appreciated
{
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);
audio.Play ();
}
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
if (Input.GetButton("Fire1") && Time.time > NextFire)
{
NextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
audioSource.Play();
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxix("Horizontal");
float moveVertical = Input.GetAxix("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
);
rb.roatation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
}
}
@rizkyjr1 What are the problems you are facing ?? If you are getting errors then post these.
Answer by rizkyjr1 · May 12, 2016 at 08:11 AM
Hi @saud_ahmed020, there are a lot of errors I do not know why. I know its a lot but I really need help :(
Answer by M-Hanssen · May 12, 2016 at 08:15 AM
What is { public float xMin, xMax, zMin, zMax; }
doing on top of your code? This is not legit.
Yes, but without the brackets and inside the class .
Answer by Positive7 · May 13, 2016 at 02:28 AM
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float xMin, xMax, zMin, zMax;
public float speed;
public float tilt;
public Boundary boundary;
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
public AudioSource audio;
public Rigidbody rigidbody;
public float nextFire;
public AudioSource audioSource;
void Update()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
audio.Play();
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(
Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax)
);
rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
Your answer
Follow this Question
Related Questions
My GameObject disappears when running this script. 0 Answers
The laser problems 0 Answers
Add 2D Skeleton to the Scene if Button was pressed 0 Answers
Integer arrays not comparing properly. 3 Answers
how do i take whats on one UI canvas and make it apear on another in real time(for a card game) 0 Answers