using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScientistController : MonoBehaviour { public GameObject frontDetector; public GameObject backDetector; public GameObject shootPoint; public GameObject shootEnd; public LayerMask playerMask; public bool isRight = false; public LineRenderer lr; public float lineWidth; public HealthController hc; public float damage = 0.1f; public float teleportInfluence = 1f; public GameObject Player; public bool teleported; // Use this for initialization void Start () { lr = GetComponent(); } // Update is called once per frame void Update () { Player = GameObject.FindGameObjectWithTag("Player"); hc = Player.GetComponent(); turn(); shoot(); Teleport(); } void Teleport() { if (Physics2D.OverlapCircle(this.transform.position,teleportInfluence,playerMask)) { if (!teleported) { transform.position = new Vector2(Player.transform.position.x - .25f, Player.transform.position.y); teleported = true; } } } void shoot() { if (Physics2D.Linecast(this.gameObject.transform.position, frontDetector.transform.position, playerMask)) { lr.enabled = true; lr.SetPosition(0, new Vector3(shootPoint.transform.position.x, shootPoint.transform.position.y, shootPoint.transform.position.z)); lr.SetPosition(1, shootEnd.transform.position); lr.startWidth = Random.Range(0.015f, 0.05f); hc.health = hc.health - damage; } else { lr.enabled = false; } if (Physics2D.Linecast(shootPoint.transform.position, shootEnd.transform.position, playerMask)) { } } void turn() { if (Physics2D.Linecast(this.gameObject.transform.position, backDetector.transform.position, playerMask)) { isRight = !isRight; } if (isRight == false) { transform.rotation = new Quaternion(0, 180, 0, 0); } else if (isRight == true) { transform.rotation = new Quaternion(0, 0, 0, 0); } } private void OnDrawGizmos() { Gizmos.DrawWireSphere(this.transform.position, teleportInfluence); } }