Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

my enemy is broken

$
0
0
so i have an enemy with this code: using UnityEngine; using System.Collections; public class enemy : MonoBehaviour { [SerializeField] private float CrabSpeed; [SerializeField] private GameObject projectile; [SerializeField] private Collider2D player; [SerializeField] private LookForShootables lfs; [SerializeField] private Collider2D radar; Quaternion zrotate; bool lookingright; bool SeePlayer; bool SeePlayerShootable; bool Triggered; private float TTN; [SerializeField] private float MTTN; private float reloadtime = 0; // Use this for initialization void Shoot(float mrt) { if (lookingright == true) zrotate = new Quaternion(0, 0, 180, 0); if (lookingright == false) zrotate = new Quaternion(0, 0, 0, 0); Rigidbody bullet; bullet = Instantiate(projectile, transform.position, zrotate) as Rigidbody; bullet.AddForce(20, 0, 0); reloadtime = reloadtime + mrt; } void TimeToNeutral() { if (TTN != 0 && Triggered == true) TTN = TTN - 1; if (TTN == 0) { Triggered = false; TTN = MTTN; } } void OnTriggerEnter2D(Collider col) { if (col.tag == "Player") { Debug.Log("holy crap!"); SeePlayer = true; } } void FixedUpdate() { SeePlayerShootable = lfs.shootables; //-------------------------------------- if (lookingright == !false) transform.localScale = new Vector3(-3, 3, 1); if (lookingright == !true) transform.localScale = new Vector3(3, 3, 1); //thesearedebugs if (Input.GetKey(KeyCode.H)) lookingright = true; if (Input.GetKey(KeyCode.G)) lookingright = false; if (reloadtime > 0) reloadtime = reloadtime - 1; //***************************************************************** //----------------------------------------------------------------- //***************************************************************** if (SeePlayer == true) { Triggered = true; Debug.Log("triggered!!!"); } if (SeePlayerShootable == true && reloadtime == 0) { Shoot(60); Debug.Log("shooting"); } if (SeePlayer == false) TimeToNeutral(); } } and another object has this: using UnityEngine; using System.Collections; public class LookForShootables : MonoBehaviour { [SerializeField] private Collider2D player; public bool shootables; void OnTriggerEnter2D(Collider col) { if (col.tag == "Player") shootables = true; } } the game is in 2d and the problem may lie with the triggers. what am i doing incorrectly? (i've only started coding so i probably did many things incorrectly.)

Viewing all articles
Browse latest Browse all 1488

Trending Articles