public void fire(Vector2 mousePos, int damage, List <GameObject> meteors) { items.Clear(); foreach (var item in meteors) { if (item != null) { MeteorScript meteorScript = item.GetComponent <MeteorScript>(); if (normalDirectionIntersect(_currentCamera.WorldToScreenPoint(item.transform.position), item.transform.localScale.x, _currentCamera.WorldToScreenPoint(mousePos), 0)) { meteorScript.flintiness -= damage; if (meteorScript.flintiness <= 0) { item.GetComponent <MeteorScript>().isDie = true; items.Add(item); } meteorScript.canDrag = false; } } } foreach (var item in items) { meteoritePointScript.Meteors.Remove(item); Destroy(item); } use = false; }
private void createMeteor(string type) { Vector3 spawnVector = Random.onUnitSphere * ((this.transform.localScale.x * 3)) + this.transform.position; GameObject newObject = Instantiate(Resources.Load(type) as GameObject, spawnVector, Quaternion.identity, this.transform); //sets the current planet of the meteor as the one where it has been created MeteorScript meteorScript = newObject.GetComponent <MeteorScript>(); meteorScript.currentPlanet = this.gameObject; }
// 玩家滑动手指碰到的陨石相当于攻击陨石一次 private List <GameObject> AttackMeteorites(Vector2 mousePos, float radius, float damage) { List <GameObject> items = new List <GameObject>(); foreach (GameObject item in meteoritePointScript.Meteors) { MeteorScript meteorScript = item.GetComponent <MeteorScript>(); if (meteorScript.canDrag && Tools.Intersect(_currentCamera.WorldToScreenPoint(item.transform.position), item.transform.localScale.x, _currentCamera.WorldToScreenPoint(mousePos), radius)) { meteorScript.flintiness -= damage; if (meteorScript.flintiness <= 0) { items.Add(item); } meteorScript.canDrag = false; } } return(items); }