void explode() { Vector3 blastPosition = GetComponent <Transform>().position; Collider[] hit = Physics.OverlapSphere(blastPosition, blastRadius); for (int i = 0; i < hit.Length; i++) { TankBehaviour tank = hit[i].GetComponent <TankBehaviour>(); if (tank != null) { float distance = (blastPosition - hit[i].GetComponent <Transform>().position).magnitude; if (distance > blastRadius) { return; } tank.takeDamage(damage * (1 - distance / blastRadius)); } } GameObject explosion = Instantiate(explodeEffect, transform.position, Quaternion.identity) as GameObject; trail.transform.parent = gameObject.transform.parent; //trail.GetComponent<ParticleSystem>().Stop(); Destroy(explosion, 3.0f); Destroy(trail, 3.0f); Destroy(gameObject); }
/// <summary> /// 组队移动 /// </summary> /// <returns>当前移动方向 + 保持间距的斥力/引力</returns> private Vector3 GetGroupMovement() { // TODO 使用碰撞体获取周围的队友 Collider[] c = Physics.OverlapSphere(position, myGroup.keepDistance, myGroup.mask); // 定义距离, Vector3 dis, v1 = Vector3.zero, v2 = Vector3.zero; // 遍历周围队友 for (int i = 0; i < c.Length; i++) { TankBehaviour otherTank = c[i].GetComponent <TankBehaviour>(); // 与该队友距离 dis = position - otherTank.position; // TODO 速度1 保持距离用 v1 += dis.normalized * (1 - dis.magnitude / myGroup.keepDistance); //查看与周围单位的距离 // TODO 速度2 加上当前移动方向 v2 += otherTank.movement; //查看周围单位移动方向 Debug.DrawLine(position, otherTank.position, Color.yellow); } // 返回 当前移动方向 + 保持间距的斥力/引力 return(v1.normalized * myGroup.keepWeight + v2.normalized * myGroup.moveWeight);//添加权重因素 }
// Start is called before the first frame update void Start() { myTransfrom = transform; tankBehaviour = GameObject.FindObjectOfType <TankBehaviour>(); _vAwal = tankBehaviour.VoPeluru; _sudutTembak = tankBehaviour.rotateValueY; _sudutMeriam = tankBehaviour.sudutMeriam; _posisiAwal = myTransfrom.position; audioSource = GetComponent <AudioSource>(); _gravity = GameObject.FindObjectOfType <TankBehaviour>().gravity; gamemanajer = GameObject.FindObjectOfType <GameManajer>(); }
private Vector3 GetGroupMovement() { Collider[] c = Physics.OverlapSphere(position, myGroup.keepDistance, myGroup.mask); //获取周围成员 Vector3 dis, v1 = Vector3.zero, v2 = Vector3.zero; for (int i = 0; i < c.Length; i++) { TankBehaviour otherTank = c [i].GetComponent <TankBehaviour> (); dis = position - otherTank.position; //距离 v1 += dis.normalized * (1 - dis.magnitude / myGroup.keepDistance); //查看与周围单位的距离 v2 += otherTank.movement; //查看周围单位移动方向 Debug.DrawLine(position, otherTank.position, Color.yellow); } return(v1.normalized * myGroup.keepWeight + v2.normalized * myGroup.moveWeight); //添加权重因素 }
public void Pickup(TankBehaviour tank) { bool healthFull = tank.health / tank.maxHealth >= healthPortionLimit; bool fuelFull = tank.fuel / tank.maxFuel >= fuelPortionLimit; if (healthFull && fuelFull) { return; } if (!healthFull) { tank.health = Mathf.Min(tank.maxHealth * healthPortionLimit, tank.health + healthAdded + tank.maxHealth * healthPortionAdded); } if (!fuelFull) { tank.fuel = Mathf.Min(tank.maxFuel * fuelPortionLimit, tank.fuel + fuelAdded + tank.maxFuel * fuelPortionAdded); } Destroy(gameObject); }
void startTurn() { int nextTankID = getValidTank((activeTankID + 1) % tanks.Length); if (nextTankID == activeTankID) { announcerText.text = "The winner is " + tanks[activeTankID].name + ", thanks for playing!!! Press esc to exit"; return; } if (nextTankID == -1) { announcerText.text = "Everyone is dead, good job"; return; } activeTankID = nextTankID; activeTank = tanks[activeTankID]; activeTankScript = tankScripts[activeTankID]; activeTankScript.fuel = activeTankScript.maxFuel; announcerText.text = "It is " + activeTank.name + "'s turn"; announcerText.color = activeTank.GetComponent <SpriteRenderer>().color; }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.GetComponent <FloorNodeComponent>()) { FloorNodeComponent fnc = hit.transform.gameObject.GetComponent <FloorNodeComponent>(); TankBehaviour tb = FindObjectOfType <TankBehaviour>(); if (fnc.istankAboveMe()) { if (tb.isTankSelected()) { tb.deselecTank(); fnc.setTankOnMe(true); } else { fnc.setTankOnMe(false); previousFNC = fnc; tb.selectTank(hit.transform.gameObject.GetComponent <FloorNodeComponent>().i_, hit.transform.gameObject.GetComponent <FloorNodeComponent>().j_); } } else { MapGenerator mg = FindObjectOfType <MapGenerator>(); int x = hit.transform.gameObject.GetComponent <FloorNodeComponent>().i_; int z = hit.transform.gameObject.GetComponent <FloorNodeComponent>().j_; if (!tb.isTankSelected()) { fnc.nextCell(); mg.table[x, z].cell = fnc.typeOfCell; } else { if (mg.table[x, z].cell != Cells.rocks) { bool action = mg.createDestiny(x, z, true); if (action) { fnc.setTankOnMe(true); } else { previousFNC.setTankOnMe(true); } } } } } } } else if (FindObjectOfType <MapGenerator>().mapGenerated&& (Input.GetAxis("Mouse X") != 0) || (Input.GetAxis("Mouse Y") != 0)) { if (FindObjectOfType <TankBehaviour>().selected&& !FindObjectOfType <TankBehaviour>().moving) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.GetComponent <FloorNodeComponent>()) { FloorNodeComponent fnc = hit.transform.gameObject.GetComponent <FloorNodeComponent>(); MapGenerator mg = FindObjectOfType <MapGenerator>(); mg.createDestiny(fnc.i_, fnc.j_, false); } } } } }