/// <summary> /// Places the object at the hit point and aligns it with the normal direction /// </summary> /// <param name="hit">hit point on the surface of another GameObject</param> /// <param name="obj">Object to place</param> private void PlaceObject(RaycastHit hit, PlacableObject obj) { GameObject spawnedObject = Instantiate <GameObject>(obj.Object, hit.point, obj.Object.transform.rotation); //Rotates the object to align with the normal direction of the hit surface spawnedObject.transform.rotation = Quaternion.FromToRotation(spawnedObject.transform.up * (obj.InvertUp ? -1 : 1), hit.normal); //Adds the object to the group spawnedObject.transform.parent = m_bufferObject.transform; RandomlyRotate(spawnedObject); }
/** * A normal member to detect Soldier has left the area of "Policko" * @param other - Collider. */ private void OnTriggerExit(Collider other) { if (other.gameObject.tag == "VojakStred") { if (occupyingObject == other.gameObject.transform.parent.gameObject) { PlacableObject placableObject = other.GetComponentInParent <PlacableObject>(); placableObject.onCollision = false; this.occupyingObject = null; } ResetColor(); } }
/** * A normal member to detect if Soldier is hovering over the "Policko" * "Policko" highlighting depends on whether it is already occupied or not * @param other - Collider. */ private void OnTriggerEnter(Collider other) { PlacableObject placableObject; if (other.gameObject.tag == "VojakStred" && !(placableObject = other.GetComponentInParent <PlacableObject>()).getIsScaled()) { if (occupyingObject == null) { HighLight(); placableObject.lastCollisionObj = transform.parent.transform; placableObject.targetPolicko = this.transform.parent.gameObject; this.occupyingObject = other.transform.parent.gameObject; } else { placableObject.lastCollisionObj = placableObject.transform; } } }
/** * A normal member checking placement of Soldiers as a required process before start of game. * @param array of Soldiers to be checked - GameObject */ private SoldierCheckState CheckSoldiers(GameObject[] soldiers) { bool noSoldiersPlaced = true; bool noSoldiersWithWeapons = true; bool soldiersRemaining = false; int scaledSoldiersCounter = 0; foreach (var soldier in soldiers) { Debug.Log(soldier.gameObject.name); PlacableObject placableObject = soldier.GetComponent <PlacableObject>(); if (!placableObject.getIsScaled()) { if (!placableObject.GetIsInSpawningArea()) { placableObject.WrongPlacement(); } soldiersRemaining = true; } else { string name = soldier.gameObject.name; Debug.Log(name); if (!name.Contains("Bait") && !name.Contains("Medic")) { noSoldiersWithWeapons = false; } noSoldiersPlaced = false; scaledSoldiersCounter++; } } if (scaledSoldiersCounter == polickoGridSize) { return(SoldierCheckState.OK); } if (noSoldiersPlaced) { Debug.Log("No soldiers placed"); standardMenu.SetActive(false); noSoldiersPlacedMenu.SetActive(true); noSoldiersWithWeaponsPlacedMenu.SetActive(false); someSoldiersLeftMenu.SetActive(false); return(SoldierCheckState.NoSoldierPlaced); } if (noSoldiersWithWeapons) { Debug.Log("No soldiers with weapons placed"); standardMenu.SetActive(false); noSoldiersPlacedMenu.SetActive(false); noSoldiersWithWeaponsPlacedMenu.SetActive(true); someSoldiersLeftMenu.SetActive(false); return(SoldierCheckState.NoSoldierPlaced); } if (soldiersRemaining) { Debug.Log("Some soldiers remaining"); standardMenu.SetActive(false); noSoldiersPlacedMenu.SetActive(false); noSoldiersWithWeaponsPlacedMenu.SetActive(false); someSoldiersLeftMenu.SetActive(true); return(SoldierCheckState.SomeSoldiersLeft); } return(SoldierCheckState.OK); }