Monday, 27 June 2011

As Shalini searched the internet for scripts, I decided to write the scripts for the movement of the car.

This is a basic layout:

using UnityEngine;
using System.Collections;

public class CarControls : MonoBehaviour
{
    #region Variables
    public float playerSpeed = 100;


    #endregion


    #region Update
    //Update per frame
    void Update()
    {
        // grab the left and right arrow key to move

        float horMov = Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime;
float verMov = Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime;

        transform.position = new Vector3(this.transform.position.x +  horMov, 
                                               this.transform.position.y + verMov ,
                                               0);

    }
    #endregion
}

No comments:

Post a Comment