topical media & game development

talk show tell print

lib-unity-presentation-Assets-Player-Scripts-PlayerScript.cs / cs



  using UnityEngine;
  using System.Collections;
  
  public class PlayerScript : MonoBehaviour {
  
      public float animspeed = 2.1f;
      private Transform myTrans;
  
      void Awake()
      {        
          
          myTrans = transform;
  
       
  
          FPSWalker fpsWalker = GetComponent<FPSWalker>();
          fpsWalker.enabled = true;
  
          playerAnimation = transform.FindChild("Graphics").FindChild("Character").animation;
          playerAnimation["Walk"].speed = animspeed;
      }
  
      private Animation playerAnimation;
      private bool isMoving = false;
      private Vector3 latestPos;
  
      void Update()
      {
         // myTrans.position = Vector3.Lerp(myTrans.position, latestPos, 25 * Time.deltaTime);
          bool wasMoving = isMoving;
          isMoving = Vector3.Distance(myTrans.position, latestPos) >= 0.01f;
          if (isMoving && !wasMoving)
          {
              playerAnimation.CrossFade("Walk");
          }
          else if (!isMoving && wasMoving)
          {
              playerAnimation.Stop();
          }
          latestPos = myTrans.position;
  
          if (Input.GetKeyDown(KeyCode.Escape))
              Application.Quit();
          
      }
  
     
      
  
      
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.