Hi guys, almost finished my first game!!! YAY
But having an issue with getting the car to turn over after it has fallen. here is the Script
using UnityEngine;
using System.Collections;
public class Driver : MonoBehaviour
{
// Update is called once per frame
void Update ()
{
if( Input.GetKey( KeyCode.W ) )
{
transform.position += transform.forward * 15.0f * Time.deltaTime;
}
if( Input.GetKey( KeyCode.A ) )
{
transform.Rotate( 0.0f, -80.0f * Time.deltaTime, 0.0f);
}
if( Input.GetKey( KeyCode.D ) )
{
transform.Rotate( 0.0f, 80.0f * Time.deltaTime, 0.0f);
}
if( Input.GetKeyDown( KeyCode.X ) )
transform.postion += Vector3.up;
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
transform.rotation = Quaternion.LookRotation(
transform.forward, Vector3.up);
}
}
}
The issue in the bottom part. I am getting the Parsing Error. I am pretty sure it is all right but, there must be something! =D
Thanks in Advance!
First off, always put your code in
blocks, so it preserves the formatting - the lack of indenting makes this very hard to read.
Secondly, your problem is probably a missing { after "KeyCode.X ))"
Two issues, first position is spelt wrong, also you had one two many } at the end of the code
Fixed and cleaned up version
public class Driver : MonoBehaviour
{
private void Update()
{
if (Input.GetKey(KeyCode.W))
{
this.transform.position += this.transform.forward * 15.0f * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A))
{
this.transform.Rotate(0.0f, -80.0f * Time.deltaTime, 0.0f);
}
if (Input.GetKey(KeyCode.D))
{
this.transform.Rotate(0.0f, 80.0f * Time.deltaTime, 0.0f);
}
if (Input.GetKeyDown(KeyCode.X))
{
this.transform.position += Vector3.up;
}
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
this.transform.rotation = Quaternion.LookRotation(this.transform.forward, Vector3.up);
}
}
Always try to format the code and use [ code] [ /code] tags (without the spaces). Easier to read code is always a good idea. You could always read http://wiki.unity3d.com/index.php/Csharp_Coding_Guidelines for some start towards nice programming style
Also can i suggest using proper titles for threads, i see two threads from you with the same title. This is not good practice and does not help fellow members if they have the same problem you may have. Just thought i would let you know 