Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SniperEnemy : Enemy
- {
- [SerializeField]
- private GameObject bullet;
- [SerializeField]
- private Transform riffleStart;
- private enum SniperState
- {
- patrol,
- prepare,
- fire
- }
- private float timer;
- private float coolDown = 5f;
- [SerializeField]
- private float area = 50f;
- private SniperState states;
- protected override void Move()
- {
- if (states == SniperState.patrol)
- {
- GetComponent<CharacterController>().Move(transform.forward * Time.deltaTime);
- if (timer>10)
- {
- transform.Rotate(new Vector3(0,90,0));
- timer = 0;
- }
- timer += Time.deltaTime;
- }
- }
- protected override void Attack()
- {
- switch(states)
- {
- case SniperState.patrol:
- if (Vector3.Distance(transform.position, player.transform.position) < area)
- {
- states = SniperState.prepare;
- timer = 0;
- }
- break;
- case SniperState.prepare:
- timer += Time.deltaTime;
- transform.LookAt(player.transform.position);
- if (timer >= coolDown)
- states = SniperState.fire;
- break;
- case SniperState.fire:
- GameObject buf = Instantiate(bullet);
- buf.transform.position = riffleStart.transform.position;
- buf.transform.rotation = transform.rotation;
- buf.GetComponent<Bullet>().setDirection(transform.forward);
- buf.GetComponent<Bullet>().MakeNewBullet(60, 80);
- timer = 0;
- states = SniperState.patrol;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement