Advertisement
Guest User

ZombieMotor

a guest
Oct 25th, 2012
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ZOMBIE MOTOR
  2. #pragma strict
  3.  
  4. var ZombieIntelligence: ZombieAI ;
  5. var animator : Animator ;
  6.  
  7. function Start () {
  8.     ZombieIntelligence = gameObject.GetComponent ( ZombieAI ); 
  9.     animator = GetComponent ( Animator ) ;
  10. }
  11.  
  12. function Update () {
  13.     animator.SetFloat ( "Speed", ZombieIntelligence.Zombie.Kombat.Speed ) ;
  14.     if ( ZombieIntelligence.Zombie.Kombat.State.TargetingPlayer )
  15.     {
  16.         FollowTarget ( ) ;
  17.         if ( ZombieIntelligence.Zombie.Kombat.Target.Distance > 7 )
  18.         {
  19.             ZombieIntelligence.Zombie.Kombat.State.Running = true ;
  20.               ZombieIntelligence.Zombie.Kombat.State.Walking = false ;
  21.             ZombieIntelligence.Zombie.Kombat.State.Attacking = false ;
  22.         }else if ( ZombieIntelligence.Zombie.Kombat.Target.Distance > 3 )
  23.         {
  24.             ZombieIntelligence.Zombie.Kombat.State.Running = false ;
  25.             ZombieIntelligence.Zombie.Kombat.State.Walking = true ;
  26.             ZombieIntelligence.Zombie.Kombat.State.Attacking = false ;
  27.         }
  28.  
  29.        
  30.     }
  31. }
  32.  
  33. function DamageFactor ( damage : float )
  34. {
  35.     if ( ZombieIntelligence.Zombie.Kombat.Health < 0 ){
  36.         Kill ( ) ;
  37.     }else{
  38.         var myForce : AddForce ;
  39.         myForce = GetComponent ( AddForce ) ;
  40.         myForce.addImpact ( Vector3.forward, 10 ) ;
  41.     }
  42.     ZombieIntelligence.Zombie.Kombat.Health -= damage * ( ZombieIntelligence.Zombie.Kombat.Defense / 100 );
  43. }
  44.  
  45. function FollowTarget ( )
  46. {
  47.     /*if ( ZombieIntelligence.Zombie.Kombat.Speed < ZombieIntelligence.Zombie.Kombat.WalkSpeed && ZombieIntelligence.Zombie.Kombat.State.Walking )
  48.     {
  49.         ZombieIntelligence.Zombie.Kombat.Speed += ZombieIntelligence.Zombie.Kombat.Velocity * Time.deltaTime ;
  50.     }else if ( ZombieIntelligence.Zombie.Kombat.Speed < ZombieIntelligence.Zombie.Kombat.RunSpeed && ZombieIntelligence.Zombie.Kombat.State.Running )
  51.     {
  52.         ZombieIntelligence.Zombie.Kombat.Speed += ZombieIntelligence.Zombie.Kombat.Velocity * Time.deltaTime ;
  53.     }*/
  54.    
  55.     if ( Mathf.Ceil ( ZombieIntelligence.Zombie.Kombat.Speed ) != 6 )
  56.     {
  57.         ZombieIntelligence.Zombie.Kombat.Speed += 1 * Time.deltaTime ;
  58.     }
  59.  
  60.     var ZTarget = ZombieIntelligence.Zombie.Kombat.Target ; // Assign Target To ZTarget
  61.     transform.position += transform.forward * ZombieIntelligence.Zombie.Kombat.Speed * Time.deltaTime; // Move Entity Toward Target
  62.  
  63.     transform.LookAt ( ZTarget.Object.transform ) ;
  64.     ///transform.rotation = Quaternion.Slerp( Vector3.zero, Quaternion.LookRotation ( ZTarget.Object.transform.position  - transform.position ), 3 * Time.deltaTime ); // Rotate Toward Target
  65. }
  66.  
  67. function Attack ( AttackType : String )
  68. {
  69.     switch ( AttackType )
  70.     {
  71.         case "Normal":
  72.  
  73.             break;
  74.     }
  75. }
  76.  
  77. function RunFromTarget ( )
  78. {
  79.     var ZTarget = ZombieIntelligence.Zombie.Kombat ; // Assign Target To ZTarget
  80.     transform.position += transform.forward * ZTarget.Speed * Time.deltaTime; // Move Entity Toward Target
  81.  
  82.     transform.rotation = Quaternion.Slerp( transform.rotation, Quaternion.LookRotation ( ZTarget.Target.Object.transform.position  + transform.position ), 3 * Time.deltaTime ); // Rotate Toward Target
  83. }
  84.  
  85. function OnCollisionEnter ( collision : Collision )
  86. {
  87.     Debug.LogError(collision.collider.tag);
  88.     switch ( collision.collider.tag ) // Read From Collisions
  89.     {
  90.         case "Player": // Case Collider = Player
  91.             ZombieIntelligence.Zombie.Kombat.Speed = 0 ;
  92.             ZombieIntelligence.Zombie.Kombat.State.Attacking = true; // Zombie State -> Attacking = true
  93.             ZombieIntelligence.Zombie.Kombat.State.Running = false ; // Zombie State -> Running = false
  94.             ZombieIntelligence.Zombie.Kombat.State.Walking = false ; // Zombie State -> Walking = false
  95.  
  96.             ZombieIntelligence.Zombie.Kombat.State.TargetingPlayer = false ;
  97.             ZombieIntelligence.Zombie.Kombat.Speed = 0;
  98.             break;
  99.     }
  100. }
  101.  
  102. function OnCollisionExit ( collision : Collision )
  103. {
  104.     switch ( collision.collider.tag ) // Read From Collisions
  105.     {
  106.         case "Player": // Case Collider = Player
  107.             ZombieIntelligence.Zombie.Kombat.State.Attacking = false; // Zombie State -> Attacking = false
  108.             ZombieIntelligence.Zombie.Kombat.State.Running = false ; // Zombie State -> Running = false
  109.             ZombieIntelligence.Zombie.Kombat.State.Walking = true ; // Zombie State -> Walking = true
  110.  
  111.             ZombieIntelligence.Zombie.Kombat.State.TargetingPlayer = true ;
  112.             break;
  113.     }
  114. }
  115.  
  116. function RecieveDamage ( damage : float )
  117. {
  118.     ZombieIntelligence.Zombie.Kombat.Health -= damage * ( ZombieIntelligence.Zombie.Kombat.Defense / 100 );
  119. }
  120.  
  121. function Kill ( )
  122. {
  123.     var RandomVectorPosition = Vector3 ( Random.Range ( 0, 100 ), Random.Range ( 10, 15 ), Random.Range ( 0, 100 ) ) ;
  124.  
  125.     ZombieIntelligence.Zombie.Kombat.Health = 100 ;
  126.     ZombieIntelligence.Zombie.Kombat.State.Attacking = false ;
  127.     ZombieIntelligence.Zombie.Kombat.State.Idle = true ;
  128.     var newInst = Instantiate ( gameObject, RandomVectorPosition, transform.rotation ) ; // Spawn New Zombie
  129.  
  130.     newInst.name = "Troll" ;
  131.     GameObject.Destroy ( gameObject ) ; // Destroy Object
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement