Day #005

DAY #005

move an object around the scene using the arrow keys.

Main points covered

#transform.Rotate

#Vector3

#time.deltaTime

 

C# script (attached to the object itself)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveship : MonoBehaviour {

public float speedmove;
public float speedrotate;


void Update () {
if (Input.GetKey(“up”)) {
transform.Translate (Vector3.forward * speedmove * Time.deltaTime);
}
if (Input.GetKey(“down”)) {
transform.Translate (Vector3.back * speedmove *Time.deltaTime);
}
if (Input.GetKey(“right”)) {
transform.Rotate (Vector3.up * speedrotate *Time.deltaTime);
}
if (Input.GetKey(“left”)) {
transform.Rotate (Vector3.down * speedrotate * Time.deltaTime);
}
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *