Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class move : MonoBehaviour
- {
- public float speed = 1f;
- public string face = "north";
- public int currentFrame = 0;
- public Transform bodyPart;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- currentFrame = currentFrame + 1;
- if (currentFrame == 30)
- {
- transform.Translate(0, 0, speed);
- Transform newBodyPart = Instantiate(bodyPart);
- newBodyPart.position = transform.position;
- currentFrame = 0;
- }
- if (face == "north")
- {
- if (Input.GetKeyDown(KeyCode.RightArrow)) {
- transform.Rotate(0, 90, 0);
- face = "east";
- }
- if (Input.GetKeyDown(KeyCode.LeftArrow))
- {
- transform.Rotate(0, -90, 0);
- face = "west";
- }
- }
- else if (face == "east")
- {
- if (Input.GetKeyDown(KeyCode.DownArrow))
- {
- transform.Rotate(0, 90, 0);
- face = "south";
- }
- if (Input.GetKeyDown(KeyCode.UpArrow))
- {
- transform.Rotate(0, -90, 0);
- face = "north";
- }
- }
- else if (face == "south")
- {
- if (Input.GetKeyDown(KeyCode.RightArrow))
- {
- transform.Rotate(0, -90, 0);
- face = "east";
- }
- if (Input.GetKeyDown(KeyCode.LeftArrow))
- {
- transform.Rotate(0, 90, 0);
- face = "west";
- }
- }
- else if (face == "west")
- {
- if (Input.GetKeyDown(KeyCode.UpArrow))
- {
- transform.Rotate(0, 90, 0);
- face = "north";
- }
- if (Input.GetKeyDown(KeyCode.DownArrow))
- {
- transform.Rotate(0, -90, 0);
- face = "south";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement