init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
51
Assets/Scripts/ShootyEnemyWeaponController.cs
Normal file
51
Assets/Scripts/ShootyEnemyWeaponController.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShootyEnemyWeaponController : GoombaAI {
|
||||
|
||||
public GameObject weaponPrefab;
|
||||
public float Range;
|
||||
|
||||
private GameObject weapon;
|
||||
private GameObject player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
weapon = Instantiate(weaponPrefab);
|
||||
weapon.name = "Weapon";
|
||||
weapon.transform.SetParent(gameObject.transform, true);
|
||||
weapon.transform.position = gameObject.transform.position;
|
||||
//weapon.transform.localScale = new Vector3(1, 1, 1);
|
||||
Destroy(weapon.GetComponent<BoxCollider2D>());
|
||||
Destroy(weapon.GetComponent<Rigidbody2D>());
|
||||
|
||||
player = findPlayer();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected void Update()
|
||||
{
|
||||
float horizontalDirection = (player.transform.position - gameObject.transform.position).x;
|
||||
float verticalDirection = (player.transform.position - gameObject.transform.position).y;
|
||||
//weapon.GetComponent<Weapon>().aim(horizontalDirection);
|
||||
|
||||
weapon.GetComponent<SpriteRenderer>().flipX = false;
|
||||
gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, horizontalDirection > 0 ? 0 : 180, 0));
|
||||
if(Mathf.Abs(horizontalDirection) < Range && Mathf.Abs(verticalDirection) < 2f) {
|
||||
weapon.GetComponent<Weapon>().shoot();
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject findPlayer() {
|
||||
GameObject player = null;
|
||||
foreach(GameObject go in FindObjectsOfTypeAll(typeof(GameObject))){
|
||||
if (go.name.Equals("Player")) {
|
||||
Debug.Log("Found player");
|
||||
player = go;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue