Transform getRandomSpawnTarget(PlateSpawner[] allTargets) { Transform tar = null; List <int> setIndex = new List <int>(); bool atOneHavePlate = false; for (int i = 0; i < spawnPoints.Length; i++) { PlateSpawner ps = spawnPoints[i]; if (ps.havePlate) { setIndex.Add(i); atOneHavePlate = true; } } if (atOneHavePlate == true) { int random = Random.Range(0, setIndex.Count); tar = spawnPoints[setIndex[random]].transform; currentPlate = spawnPoints[setIndex[random]]; targetType = TargetType.Spawns; } return(tar); }
Transform nearSpawnTarget(PlateSpawner[] allTargets) { Transform tar = null; float dis = float.MaxValue; int index = 0; bool atOneHavePlate = false; for (int i = 0; i < spawnPoints.Length; i++) { PlateSpawner ps = spawnPoints[i]; float itsDistance = Vector3.Distance(transform.position, ps.transform.position); if (ps.havePlate && itsDistance < dis) { dis = itsDistance; index = i; atOneHavePlate = true; } } if (atOneHavePlate == true) { tar = spawnPoints[index].transform; currentPlate = spawnPoints[index]; targetType = TargetType.Spawns; } return(tar); }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag(TagsLayers.spawnPointTag)) { PlateSpawner ps = collision.gameObject.GetComponent <PlateSpawner>(); if (ps != null && ps.havePlate) { CarryPlate(ps); } } if (collision.gameObject.CompareTag(TagsLayers.tableTag)) { if (plates.Count != 0 && collision.gameObject.GetComponent <Table>() == SpawnsTables.currentDeliverTable) { powerHandler.updateScale(plates.Count); foreach (Transform t in plates) { Destroy(t.gameObject); } plates.Clear(); SpawnsTables.changeDeliverTable(); } } if (collision.gameObject.CompareTag(TagsLayers.enemyTag)) { Interactor.handleInteraction(this, collision.gameObject.GetComponent <EnemyController>()); } }
void carryPlate(PlateSpawner ps) { if (ps.havePlate == false) { return; } Transform t = ps.getPlate(); plates.Add(t); t.SetParent(platesHolder); t.localPosition = Vector3.zero; t.localRotation = Quaternion.identity; t.localPosition = t.up * 0.1f * (plates.Count - 1); }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag(TagsLayers.spawnPointTag)) { navAgent.ResetPath(); if (enemyState != ENEMYSTATE.Dodged) { carryPlate(collision.gameObject.GetComponent <PlateSpawner>()); } } if (collision.gameObject.CompareTag(TagsLayers.tableTag)) { navAgent.ResetPath(); targetType = TargetType.None; currentPlate = null; currentPC = null; currentEC = null; if (enemyState != ENEMYSTATE.Dodged && plates.Count != 0 && collision.gameObject.GetComponent <Table>() == SpawnsTables.currentDeliverTable) { powerHandler.updateScale(plates.Count); foreach (Transform t in plates) { Destroy(t.gameObject); } plates.Clear(); SpawnsTables.changeDeliverTable(); } } if (collision.gameObject.CompareTag(TagsLayers.playerTag)) { Interactor.handleInteraction(this, collision.gameObject.GetComponent <PlayerController>()); } if (collision.gameObject.CompareTag(TagsLayers.enemyTag)) { Interactor.handleInteraction(this, collision.gameObject.GetComponent <EnemyController>()); } }
void CarryPlate(PlateSpawner ps) { if (playerState == PLAYERSTATE.Dodged) { return; } if (joyStick.minDisMoved(minInputDistance)) { playerState = PLAYERSTATE.CarryRun; } else { playerState = PLAYERSTATE.CarryIdle; } Transform t = ps.getPlate(); plates.Add(t); t.SetParent(platesHolder); t.localPosition = Vector3.zero; t.localRotation = Quaternion.identity; t.localPosition = t.up * plateStackDistance * (plates.Count - 1); }
void Awake() { instance = this; }