void Start() { player = FindObjectOfType <PlayerController>(); playerShootingHandler = player.GetComponent <ShootingHandler>(); agent = GetComponent <NavMeshAgent>(); shootingHandler = GetComponent <EnemyAttack>(); playerShootingHandler.onShootEvent += OnPlayerShoot; }
private void SetupWeaponHandler(List <IWeaponItem> primaryWeapons, List <IWeaponItem> alternativeWeapons, List <IWeaponItem> secondaryWeapons) { if (shipStats.primaryWeaponInfo.isEnabled) { primaryWeaponHandler = this.gameObject.AddComponent <ShootingHandler>(); primaryWeaponHandler.Init(controller.statHandler, primaryWeapons, shipStats, shipStats.primaryWeaponInfo); } if (shipStats.alternativeWeaponInfo.isEnabled) { alternativeWeaponHandler = this.gameObject.AddComponent <ShootingHandler>(); alternativeWeaponHandler.Init(controller.statHandler, alternativeWeapons, shipStats, shipStats.alternativeWeaponInfo); } if (shipStats.secondaryWeaponInfo.isEnabled) { secondaryWeaponHandler = this.gameObject.AddComponent <ShootingHandler>(); secondaryWeaponHandler.Init(controller.statHandler, secondaryWeapons, shipStats, shipStats.secondaryWeaponInfo); } }
private void Start() { shootingHandler = GetComponent <ShootingHandler>(); }
private void Awake() { movementHandler = GetComponent <MovementHandler>(); shootingHandler = GetComponent <ShootingHandler>(); }
void shoot(Vector3 position, Vector3 direction, bool audioFlag) { //Camera cam = Camera.main; //Debug.Log("shoot"); RaycastHit hit = new RaycastHit(); Ray ray = new Ray(position, direction); if (Physics.Raycast(ray, out hit)) { Debug.Log("hit name:" + hit.collider.name); string tag = hit.collider.tag; ShootingHandler sh = hit.collider.gameObject.GetComponent <ShootingHandler>(); if (sh != null) { //Debug.Log("shooting handler working."); sh.gotShot(); } else if (tag == "animal" || tag == "bird") { placeBullet(hit.point); //animal handling AnimalAnimation animA = hit.collider.gameObject.GetComponent <AnimalAnimation>(); if (animA) { animA.gotShot(); } //bird handling else { BirdAnim animB = hit.collider.gameObject.GetComponent <BirdAnim>(); if (animB) { animB.gotShot(); } } } else if (tag == "run train") { if (distance(hit.point) < _trainTriggerDist) { Data.triggerObj = hit.collider.gameObject; runTrain(false); } } else if (tag == "train ride") { if (distance(hit.point) < _trainTriggerDist) { Data.triggerObj = hit.collider.gameObject; runTrain(true); } } else if (tag == "vehicle") { if (distance(hit.point) < _trainTriggerDist) { Debug.Log("vehcle running."); startDrive(hit); //runTrain(true); } } else if (tag == "reflector") { Vector3 newDir = getReflection(direction, hit.collider.transform.forward); Debug.Log("reflector:" + hit.collider.name + "\tinbound:" + direction + "normal:" + hit.collider.transform.forward + "point:" + hit.point + "dir:" + newDir);; shoot(hit.point, newDir, false); } else { placeBullet(hit.point); } } if (audioFlag) { if (_src == null) { _src = gameObject.AddComponent <AudioSource>(); } _src.PlayOneShot(sound); } }