- Home /
This question was
closed Jan 23, 2015 at 05:31 PM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
E3S21I · Jan 23, 2015 at 09:49 AM ·
script error
PlayerController C# Script error? Help!
Theres a problem with my script 1) Keyword void' cannot be used in this context 2) Unexpected symbol
(', expecting )',
,', ;',
[', or `='
Can anyone help me out?
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
void Update ()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
{
}
void FixedUpdate ()
{
if(Input.GetKeyDown("A"))
animation.Play("PlayerLeft");
if(Input.GetKeyDown("D"))
animation.Play("PlayerRight");
if (Input.GetKey(KeyCode.D))
transform.position += new Vector3(speed + Time.deltaTime, 0.0f, 0.0f);
if (Input.GetKey(KeyCode.A))
transform.position -= new Vector3(speed + Time.deltaTime, 0.0f, 0.0f);
}
}
Comment
Best Answer
Answer by tanoshimi · Jan 23, 2015 at 09:49 AM
Your Update function is wrong.
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
{
should be
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
Embarrassing indeed! Always use a code editor which highlights brackets.
Follow this Question
Related Questions
OnTriggerExit with 2D Colliders? 1 Answer
Fps controller script error 0 Answers
Script error 1 Answer
Something is wrong with unity 0 Answers