Facebook
From Burly Elephant, 7 Years ago, written in C#.
This paste is a reply to Untitled from Soiled Pudu - view diff
Embed
Download Paste or View Raw
Hits: 365
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class OrcMovement : MonoBehaviour
  5. {
  6.     public float speed = 4;
  7.  
  8.     public bool isWalking;
  9.     private Animator animation;
  10.  
  11.     Rigidbody2D rigidbody;
  12.        
  13.         void Start()
  14.     {
  15.         rigidbody = GetComponent<Rigidbody2D>();
  16.         rigidbody.gravityScale = 1;
  17.         animation = GetComponent<Animator>();
  18.        
  19.     }
  20.  
  21.     void Update()
  22.     {
  23.         if (transform.position.x > 1)
  24.         {
  25.             rigidbody.velocity = new Vector2(transform.right.x * speed * -1, 0);
  26.             isWalking = true;
  27.             animation.SetBool("isWalking", isWalking);
  28.         }else
  29.         {
  30.             rigidbody.velocity = new Vector2(0, 0);
  31.             isWalking = false;
  32.             animation.SetBool("isWalking", isWalking);
  33.         }
  34.     }
  35. }
  36.