public void Init(UNITFACTION f) { faction = f; switch (faction) { case UNITFACTION.PLAYER: joysticks = managerGame.controlJoysticks; break; case UNITFACTION.ENEMY: agent.isStopped = false; break; } controller.detectCollisions = rb.detectCollisions = true; //Set statsUI behaviour. statsUI.tTarget = transform; statsUI.Init(faction); //Stats hpCurrent = hpBase; UpdateUI_HP(); isActive = true; }
// To be fixed by twaeking enemies to use colliders, not controllers. private void OnControllerColliderHit(ControllerColliderHit hit) { Debug.Log(hit.gameObject.name); if (hit.gameObject.tag == "UNIT") { // Get colliding unit's faction UNITFACTION colliderFaction = hit.gameObject.GetComponent <Unit>().faction; switch (faction) { case UNITFACTION.PLAYER: if (colliderFaction == UNITFACTION.ENEMY) { NavMeshAgent a = hit.gameObject.GetComponent <NavMeshAgent>(); Knockback(a.velocity); } break; case UNITFACTION.ENEMY: if (colliderFaction == UNITFACTION.PLAYER) { Knockback(hit.rigidbody.velocity); } break; } } }
public void Init(UNITFACTION faction) { sliderHP.value = 1f; sliderOverheat.value = 0f; if (faction == UNITFACTION.PLAYER) { //Turn on Overheat. sliderOverheat.gameObject.SetActive(true); } else if (faction == UNITFACTION.ENEMY) { sliderOverheat.gameObject.SetActive(false); } this.gameObject.SetActive(true); }
private void SpawnUnit(UNITFACTION faction, UNITTYPE type) { // Spawn unit gameobject first. Unit unitToSpawn = SpawnOrRecycleUnit(type); // Attach a stats UI to it as well. unitToSpawn.statsUI = SpawnOrRecycleStatsUI(); if (faction == UNITFACTION.PLAYER) { // Set camera focus on unit. camOrtho.Follow = unitToSpawn.transform; unitPlayer = unitToSpawn; unitToSpawn.transform.position = new Vector3(0f, 0f, 1f); } else if (faction == UNITFACTION.ENEMY) { // Find the furthest spawn point from player. unitToSpawn.transform.position = GetFurthestSpawnPoint(); } unitToSpawn.gameObject.SetActive(true); unitToSpawn.Init(faction); }