Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class move : MonoBehaviour
  6. {
  7.     public float speed = 1f;
  8.     public string face = "north";
  9.     public int currentFrame = 0;
  10.  
  11.     public Transform bodyPart;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.        
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         currentFrame = currentFrame + 1;
  23.         if (currentFrame == 30)
  24.         {
  25.             transform.Translate(0, 0, speed);
  26.  
  27.             Transform newBodyPart = Instantiate(bodyPart);
  28.             newBodyPart.position = transform.position;
  29.  
  30.             currentFrame = 0;
  31.         }
  32.        
  33.  
  34.         if (face == "north")
  35.         {
  36.             if (Input.GetKeyDown(KeyCode.RightArrow)) {
  37.                 transform.Rotate(0, 90, 0);
  38.                 face = "east";
  39.             }
  40.  
  41.             if (Input.GetKeyDown(KeyCode.LeftArrow))
  42.             {
  43.                 transform.Rotate(0, -90, 0);
  44.                 face = "west";
  45.             }
  46.         }
  47.  
  48.         else if (face == "east")
  49.         {
  50.             if (Input.GetKeyDown(KeyCode.DownArrow))
  51.             {
  52.                 transform.Rotate(0, 90, 0);
  53.                 face = "south";
  54.             }
  55.  
  56.             if (Input.GetKeyDown(KeyCode.UpArrow))
  57.             {
  58.                 transform.Rotate(0, -90, 0);
  59.                 face = "north";
  60.             }
  61.         }
  62.  
  63.         else if (face == "south")
  64.         {
  65.             if (Input.GetKeyDown(KeyCode.RightArrow))
  66.             {
  67.                 transform.Rotate(0, -90, 0);
  68.                 face = "east";
  69.             }
  70.  
  71.             if (Input.GetKeyDown(KeyCode.LeftArrow))
  72.             {
  73.                 transform.Rotate(0, 90, 0);
  74.                 face = "west";
  75.             }
  76.         }
  77.  
  78.         else if (face == "west")
  79.         {
  80.             if (Input.GetKeyDown(KeyCode.UpArrow))
  81.             {
  82.                 transform.Rotate(0, 90, 0);
  83.                 face = "north";
  84.             }
  85.  
  86.             if (Input.GetKeyDown(KeyCode.DownArrow))
  87.             {
  88.                 transform.Rotate(0, -90, 0);
  89.                 face = "south";
  90.             }
  91.         }
  92.  
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement