Menu
CoddyTech

Recap: Drive the Cube

Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 6 of 67.

challenge icon

Challenge

Easy

Put the chapter together in one script:

  • When the game starts, place the cube on the ground at x = -3 and z = 0 (it is 1 unit tall).
  • While the right arrow is held, it drives right along x at speed units per second.
  • While Space is held, it spins around its y axis at spin degrees per second.

Press Play to drive it, then Check.

Try it yourself

using UnityEngine;

public class Driver : MonoBehaviour
{
    public float speed = 3f;
    public float spin = 180f;

    void Start()
    {
    }

    void Update()
    {
    }
}

All lessons in Unity Scripting Basics