public void Start() { rayDirection = new Vector2(1, 0); QDirection = new Quaternion(1, 0, 0, 0); PlayerPosition = new Vector3(0, 0, 0); Front = 1; _Player = GameManager.Instance.LocalPlayer; Rotate = 360; PrevTime = Time.time; raydistance = 100; AttackTime = Time.time; attack = true; This_State = MON_STATE.IDLE; CanHit = true; FX = GameManager.Instance.SoundManager; Map_Size = transform.parent.parent.GetComponent <SpriteRenderer>().size; }
// Update is called once per frame public void Update() { if (_Player == null) { return; } if (transform.localPosition.y >= Map_Size.y / 2 || transform.localPosition.y <= -Map_Size.y / 2 || transform.localPosition.x >= Map_Size.x / 2 || transform.localPosition.x <= -Map_Size.x / 2) { transform.position = _Player.transform.position; } //Debug.Log(This_State); ThisTime = Time.time; QDirection = QDirection * Quaternion.Euler(0, 0, Rotate * Time.deltaTime * 4); rayDirection.x = QDirection.x; rayDirection.y = QDirection.y; rayDirection.Normalize(); Inverse_rayDirection = -rayDirection; ray = new Ray2D(transform.position, rayDirection); hit = Physics2D.Raycast(ray.origin, ray.direction, raydistance, 9); if (!attack && This_State != MON_STATE.ATTACK) { if (ThisTime - AttackTime >= AR) { attack = true; } } if (hit.collider != null && hit.transform.tag == "Player" && This_State != MON_STATE.ATTACK && This_State != MON_STATE.DIRECTATTACK) { PlayerPosition = hit.transform.position; This_State = MON_STATE.TRACKING; PrevTime = Time.time; } switch (This_State) { case MON_STATE.IDLE: STATE_IDLE(); break; case MON_STATE.IDLE_MOVE: STATE_IDLE_MOVE(); break; case MON_STATE.TRACKING: STATE_TRACKING(); break; case MON_STATE.MISS: STATE_MISS(); break; case MON_STATE.ATTACK: STATE_ATTACK(); break; case MON_STATE.DIRECTATTACK: STATE_DIRECTATTACK(); break; } }