// explode the grenade, injure those nearby public void explode() { Character_BS userChar = User.GetComponent <Character_BS>(); GameStateBS GAMESTATE = userChar.GAMESTATE; foreach (GameObject go in GAMESTATE.ALL_CHARACTERS) { float dist = Vector3.Distance(go.transform.position, transform.position); if (dist <= explosionRadius) { Character_BS targetChar = go.GetComponent <Character_BS>(); int realDam = Mathf.FloorToInt(damage * (1 - dist * damageDropoff)); // SET MIN DEPTH TO 1, so grenade wont be hit! RaycastHit2D[] hitInfo = Physics2D.RaycastAll(transform.position, go.transform.position - transform.position, dist, -1, 1); Collider2D targColl = go.GetComponent <Collider2D>(); Collider2D grenColl = GetComponent <Collider2D>(); bool isHit = true; foreach (RaycastHit2D hit in hitInfo) { if (hit.collider == null || hit.collider == targColl) { // could be target, could be nothing } else if (hit.collider == grenColl) { // grenade hit itself } else { // grenade hit a wall, stops the hit from being processed isHit = false; //print("Missed: " + hit.collider.gameObject); } } if (isHit == true) { //print("Hit: " + targetChar.gameObject); targetChar.hitByExplosion(this, realDam); } } } if (shotClip != null) { AudioSource.PlayClipAtPoint(shotClip, transform.position); } GAMESTATE.MakeNoise(gameObject, transform.position, explodeVolume); GameObject.Destroy(gameObject, 0.05f); }
// Use this for initialization void Start() { // check character obj exists if (character == null) { character = gameObject.GetComponent <Character_BS>(); } // check if gamestate reference exists if (GAMESTATE == null) { GAMESTATE = gameObject.GetComponentInParent <GameStateBS>(); } // check for target // TODO do that... }
float minForgetDistance = 0.05f; // completely forget a soft target if we get within this distance // Use this for initialization void Start() { // check character obj exists if (character == null) { character = gameObject.GetComponent <Character_BS>(); } // check if gamestate reference exists if (GAMESTATE == null) { GAMESTATE = gameObject.GetComponentInParent <GameStateBS>(); } softTarget = transform.position; // set target to where we already are }
// Use this for initialization void Start() { rigidbod = GetComponent <Rigidbody2D>(); // check if gamestate reference exists if (GAMESTATE == null) { GAMESTATE = gameObject.GetComponentInParent <GameStateBS>(); } List <ItemBS> subitems = new List <ItemBS>(); subitems.AddRange(gameObject.GetComponentsInChildren <ItemBS>()); // TODO: This only detects active objects! foreach (ItemBS i in subitems) { if (false == inventory.Contains(i)) { inventory.Add(i); } } }
// Use this for initialization void Start() { OBJECTIVES.AddRange(GetComponentsInChildren <ObjectiveBS>()); GAMESTATE = GetComponentInParent <GameStateBS>(); }
// Use this for initialization void Start() { ZombiesLeft = Mathf.CeilToInt(Random.Range(smallHerd, largeHerd)); GAMESTATE = GetComponent <GameStateBS>(); }
// Use this for initialization void Start() { GAMESTATE = GetComponentInParent <GameStateBS>(); }