void OnTriggerEnter(Collider other) { if (!hasAuthority) { return; } if (other.GetComponent <NetworkIdentity> ().hasAuthority) { return; } if (other.name.Contains("Ant")) { if (other.GetComponent <BasicAnt>() != null) { WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DamageBasicAnt(other.gameObject, Random.Range(0, beatleDamage), gameObject); Destroy(gameObject); } } if (other.tag == "anthill") { if (other.GetComponent <Anthill>().health <= 0) { GameObject.Find("Canvas").transform.FindChild("Victory").gameObject.SetActive(true); // WorldHandler is always checking for these to be true or false to switch scenes to defeat/victory } WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DamageAntHill(other.gameObject, Random.Range(0, beatleDamage), gameObject); } }
public void spawnBasicAntUnit() { if (hasAuthority) { WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>(); if (WorldHandler.countUnits() < localPlayer.maxUnits) { // if you have less units than the max number of units, it is okay to spawn more units. if (localPlayer.resourcesCount > localPlayer.BasicAntCost) { // if you have enough unit space and you have enough resources Cmd_SpawnAntUnit(transform.position); localPlayer.resourcesCount -= localPlayer.BasicAntCost; // after spawning unit, spend 15 resources. } else if (localPlayer.resourcesCount < localPlayer.BasicAntCost) { WorldHandler.PlayResourcesSound(); // You require more resources (audio clip); } } else if (WorldHandler.countUnits() > localPlayer.maxUnits) { WorldHandler.PlayUnitCapSound(); // You require more unit Cap audio clip (this is if we decide to add a way for the player to increase the unit cap); } } }
// Update is called once per frame void Update() { beatlePosition = new Vector3(transform.position.x, WorldHandler.CAMERA_Y, transform.position.z); // not sure if i should add a transform.hasChanged test so it doesnt call this every frame? timer += Time.deltaTime; if (health <= 0) { gameObject.SetActive(false); WorldHandler.unitsSelected.Remove(gameObject); isUnitSelected = false; WorldHandler.DestroyFlags(); GetComponent <Collider>().isTrigger = false; if (isServer) { WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DespawnObject(gameObject); } } if (isUnitSelected) { displayBeatleInfo(); } if (beatlePosition != Vector3.zero) { // when space is pressed, move camera to the anthill if (Input.GetKey(KeyCode.Space) && isUnitSelected) { Camera.main.transform.position = beatlePosition; Debug.Log(beatlePosition); } } }
/// <summary> /// If your mouse is being right clicked over an ant you don't own and you have a beatle unit selected, check the range to see if it is less than BEATLE_RANGE, if it is less, stop the Navigation and fire projectile. /// </summary> void OnMouseOver() { // For Beatle Ranged Attacks // setup Timer for atk Spd if (Input.GetMouseButtonDown(1)) { if (!hasAuthority) { // if it is not owned by you if (WorldHandler.isBeatleUnitSelected()) { // for beatle ranged units ArrayList beatles = WorldHandler.getBeatleUnitsAsArray(); foreach (GameObject beatle in beatles) { float range = beatle.GetComponent <Beatle>().Range; Debug.Log("Beatle Range: " + range); Debug.Log("Distance from ant and the beatle: " + Vector3.Distance(transform.position, beatle.transform.position)); if (Vector3.Distance(transform.position, beatle.transform.position) <= range) { WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>(); localPlayer.Cmd_FireProjectile(beatle, transform.position); } } } // end beatle ranged units } } }
private void fireAfterWait(GameObject beatle, Vector3 target) { GameObject bullet = Resources.Load("Prefabs/bomb") as GameObject; // bullet prefab GameObject bulletToSpawn = (GameObject)Instantiate(bullet, beatle.transform.position, beatle.transform.rotation); // antstospawn // Set after it is spawned bulletToSpawn.GetComponent <FireBeatleBullet>().positionToFireAt = target; // spawns the bullet and then feeds it a vector3 of the position of the ant its being fired at (this ant). NetworkServer.SpawnWithClientAuthority(bulletToSpawn, WorldHandler.findLocalPlayer()); }
// end timers void Start() { localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler> (); anthillInfo = GameObject.Find("Canvas").transform.FindChild("SpawnAttackAnt").gameObject; fpsText = GameObject.Find("FPSCounter").GetComponent <Text>(); unitCapText = GameObject.Find("UnitCap").transform.FindChild("Text").GetComponent <Text> (); gameTimerText = GameObject.Find("GameTimer").transform.FindChild("Text").GetComponent <Text> (); resourcesCountText = GameObject.Find("ResourcesCount").transform.FindChild("Text").GetComponent <Text> (); scrollText = GameObject.Find("ScrollBackground").transform.FindChild("Text").gameObject; EscapeMenu = GameObject.Find("Canvas").transform.FindChild("EscapeMenu").gameObject; Cursor.lockState = CursorLockMode.Confined; chatLogs.Callback = OnChatUpdate; // chatlog inputField = GameObject.Find("EnterMessage"); // of type InputField }
void Start() { //healthBar = transform.FindChild ("Canvas").FindChild ("HealthBar").gameObject; localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler> (); unitInfo = GameObject.Find("Canvas").gameObject.transform.FindChild("UnitInfo").gameObject; maxHealth = 100; health = 100; damage = 15; AttackSpeed = 2; if (gameObject.name.Contains("RedAnt(Clone)") || gameObject.name.Contains("BlueAnt(Clone)")) { gameObject.name = "Ant"; } }
void OnTriggerStay(Collider other) { if (other.GetComponent <UnitIdentity> () == null) { return; } if (other.GetComponent <UnitIdentity> ().id == GetComponent <UnitIdentity> ().id) { return; } if (timer >= AttackSpeed) { timer = 0; } else { return; } if (other.tag == "anthill") { if (other.GetComponent <Anthill> ().health <= 0) { GameObject.Find("Canvas").transform.FindChild("Victory").gameObject.SetActive(true); } else { localPlayer.Cmd_dealDamage(gameObject, other.gameObject); } Debug.Log("anthill detected"); } if (other.tag == "unit") { if (other.GetComponent <Beatle>()) { other.GetComponent <Animation>().CrossFade("fire"); } if (other.GetComponent <BasicAnt>()) { other.GetComponent <Animation>().CrossFade("ant-bite"); } Debug.Log("works"); if (localPlayer == null) { localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler> (); } localPlayer.Cmd_dealDamage(gameObject, other.gameObject); } if (other.GetComponent <UnitIdentity> ().id != GetComponent <UnitIdentity> ().id&& other.GetComponent <Anthill>() == null) { other.transform.LookAt(transform); transform.LookAt(other.transform); } }