Day #004

DAY #003

move an object around the scene using the arrow keys.

Main points covered

#transform.Translate

#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;

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.Translate (Vector3.right * speedmove *Time.deltaTime);
}
if (Input.GetKey(“left”)) {
transform.Translate (Vector3.left * speedmove * Time.deltaTime);
}
}
}

Leave a Reply

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