Esempio n. 1
0
 private void Update()
 {
     losToPlayer = false;
     if ((player.transform.position - transform.position).sqrMagnitude <= sightRange * sightRange)
     {
         losToPlayer = Utility.lineOfSight(gameObject, player);
     }
     if (losToPlayer)
     {
         if (!fearParticles.isPlaying)
         {
             fearParticles.Play();
         }
     }
     else
     {
         if (fearParticles.isPlaying)
         {
             fearParticles.Stop();
         }
     }
     if (rb2d.velocity.magnitude < 0.1f)
     {
         hm.addIntegrity(healsPerSecond * Time.deltaTime);
         if (hm.getIntegrity() == hm.maxIntegrity)
         {
             healing = false;
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (activeMove && isGrounded())
     {
         float tempSpeed = speed;
         if (rb2d.velocity.magnitude < speed / 4)
         {
             tempSpeed *= speed * 2;
         }
         if (hm.getIntegrity() < hm.maxIntegrity / 4 || healing)
         {
             healing   = true;
             tempSpeed = 0;
         }
         if (tempSpeed > 0)
         {
             rb2d.AddForce(rb2d.mass * direction * tempSpeed);
         }
         if (rb2d.velocity.magnitude > maxSpeedReached)
         {
             maxSpeedReached = rb2d.velocity.magnitude;
         }
         //Cliff detection
         if (senseInFront() == null)                       //there's a cliff up ahead
         {
             if (!Utility.lineOfSight(gameObject, player)) //nothing between it and the player
             {
                 switchDirection();
                 rb2d.AddForce(rb2d.mass * direction * rb2d.velocity.magnitude * 4);
             }
         }
         if (rb2d.velocity.magnitude < 0.01f)
         {
             switchDirection();
         }
     }
     if (rb2d.velocity.magnitude < 0.1f)
     {
         hm.addIntegrity(healsPerSecond * Time.deltaTime);
         if (hm.getIntegrity() == hm.maxIntegrity)
         {
             healing = false;
         }
     }
 }