Moving Square

My first step!

A box that moves on a green background. I know it’s not really a big step, and it took me way too long, but it got done. Just a simple script that allows unity to grab your arrow inputs and moves the square in two dimensions. I don’t have border conditions or another square, or collisions … or anything, it just works. I know how to make the executable, which was my task for today.

Here’s the link to the box “game.”

Next step? Border conditions!

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

public class SquareMove : MonoBehaviour {
    public float speed = 1.5f;

    void Update () {
        if (Input.GetKey(KeyCode.LeftArrow))
            transform.position += Vector3.left * speed * Time.deltaTime;
        if (Input.GetKey(KeyCode.RightArrow))
            transform.position += Vector3.right * speed * Time.deltaTime;
        if (Input.GetKey(KeyCode.UpArrow))
            transform.position += Vector3.up * speed * Time.deltaTime;
        if (Input.GetKey(KeyCode.DownArrow))
            transform.position += Vector3.down * speed * Time.deltaTime;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s