Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: AimPlayer
  3. // Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: A258C9B1-E700-457A-BAE7-06EFF4747DB4
  5. // Assembly location: /Volumes/T5_1TB/Projects/WakeApp/23_Petr/build/TestWakeApp_Data/Managed/Assembly-CSharp.dll
  6.  
  7. using UnityEngine;
  8.  
  9. public class AimPlayer : MonoBehaviour
  10. {
  11.   public float power = 1f;
  12.   public float rayDistance = 1f;
  13.   public GameObject Gun;
  14.   public Transform player;
  15.   public int fireRange;
  16.   public Transform enemy;
  17.   public float speedRotation;
  18.   public float speeedMove;
  19.   public GameObject bulletPref;
  20.   public Transform muzzle;
  21.   public GameObject bullet;
  22.  
  23.   private bool IsReadyToFire
  24.   {
  25.     get
  26.     {
  27.       return (double) Vector3.Distance(this.transform.position, this.player.transform.position) <= (double) this.fireRange;
  28.     }
  29.   }
  30.  
  31.   private void Start()
  32.   {
  33.   }
  34.  
  35.   private void AiBot()
  36.   {
  37.     this.enemy.rotation = Quaternion.Slerp(this.enemy.rotation, Quaternion.LookRotation(this.player.position - this.enemy.position), this.speedRotation * Time.deltaTime);
  38.     if (this.IsReadyToFire)
  39.     {
  40.       Ray ray = new Ray(this.transform.position, this.transform.forward);
  41.       RaycastHit hitInfo;
  42.       Physics.Raycast(ray, out hitInfo, (float) this.fireRange);
  43.       Debug.DrawRay(ray.origin, ray.direction * (float) this.fireRange, Color.blue);
  44.       if (!((Object) hitInfo.collider != (Object) null) || !hitInfo.collider.CompareTag("Mob"))
  45.         return;
  46.       this.bullet = Object.Instantiate<GameObject>(this.bulletPref, this.muzzle.position, this.muzzle.rotation);
  47.       this.bullet.GetComponent<Rigidbody>().AddForce(this.bullet.transform.forward * this.power, ForceMode.Impulse);
  48.       Object.Destroy((Object) this.bullet, 2f);
  49.     }
  50.     else
  51.       this.enemy.transform.position += this.enemy.forward * this.speeedMove * Time.deltaTime;
  52.   }
  53.  
  54.   private void Update()
  55.   {
  56.     this.AiBot();
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement