// Start is called before the first frame update void Awake() { startingPos = transform.position; startingRot = transform.rotation; Data data = Data.instance; graph = data.graph; try { humanBehaviour = GetComponent <HumanBehaviour>(); if (humanBehaviour == null) { throw new MissingComponentException(); } } catch (MissingComponentException componentException) { gameObject.AddComponent(typeof(HumanBehaviour)); Debug.LogWarning("Couldn't find a guard behavior on object: " + gameObject.name + "... Therefore script added the guardbehavior component"); } try { if (data.graph == null) { throw new NullReferenceException(); } } catch (NullReferenceException nullException) { Debug.LogWarning("Graph or target might not be set in inspector"); } path = new Path(data.graph, transform.position, new Vector3(0, 0, 0)); heardTarget = null; }
private void MakeNewHuman() { Direction = Random.value < 0.5f ? 1 : -1; do { y = (float)Random.Range(-4, 6); } while (last_y == y); last_y = y; // Ok, it says y but I actually need to use Z now cause I switched to faux2d with a 3d camera int color_id = Random.Range(0, possibleColours.Length); location = new Vector3(Direction * 9, 0f, y * DIST_BETW_HUMANS + (Random.value - 0.5f) / 5f); GameObject human = Instantiate(humanPrefab, location, transform.rotation); HumanBehaviour hb = human.GetComponent <HumanBehaviour>(); hb.WALK_SPEED = Random.Range(1f, 2f); hb.SetColour(possibleColours[color_id]); // print(wantedManager); HumanFeatures hf; hf = GenerateHumanFeatures(); // do { hf = GenerateHumanFeatures(); } // while (wantedManager.CheckContain(hf) && Random.value < 0.95f); hb.SetDirection(Direction); hb.SetFeatures(hf); }
//Function used to run the update (originally in void update but moved here to enable a last update before saving private void runUpdate() { TimeSpan t = (WORLDTIME.WORLDTIME - lastUpdate); int minutesSince = (int)t.TotalMinutes; Debug.Log("Hydration: " + entityNeeds.hydration); updateRequired = false; entityNeeds.updateSurvivalNeeds(minutesSince); //do stuff here //Guaranteed to do perform entity needs if (!currentlyBusy && (entityNeeds.isInNeed())) { HumanBehaviour.humanNeedsBehaviour(ref HUMANROOT); } //If not setup to perform standard need/task below else { overrideEntityNeeds = true; } //Perform standard need/task if (overrideEntityNeeds) { //perform standard task } overrideEntityNeeds = false; lastUpdate = WORLDTIME.WORLDTIME; nextUpdate -= 10.0f; }
public void createHumanPiece( HumanBehaviour.HUMAN_TYPE m_HumanType ) { // Todo: check the position //var startPiece = new GamePiece(new Point(2, 2)); // Position provide by var startPiece = new GamePiece(GetAvailablePosition() ); // Position provide by GameObject NewHuman = CreatePiece_Human(startPiece, m_HumanType); NewHuman.transform.parent = Actor_Humans.transform ; NewHuman.name = "Human_Adam"; //Actor_Humans _gamePieces_Humans.Add(NewHuman); }
// I think that both the following bugs could be fixed with some use of OnTriggerStay? /* BUG * Going from Idle to Chasing does not disable BoxOfSight correctly... * This is what happens in OnTriggerEnter: If (isIdle) and we see a player then StartChasing(); * StartChasing will set isIdle = false, so next If statement is entered... * This next if statement sets targetContact = true, which is used in ChaseMove to slow the player * Effect: Zombies will slow you if they can see you. */ /* BUG * If you are inside BoxOfSight but Physics.Raycast does not hit you * then you stand in obvious line of sight, Physics.Raycast is not called again * so the zombie does not chase you. * Effect: Zombies might not chase you if they first 'see' you whilst you're behind something */ void OnTriggerEnter(Collider collider) { if (collider.tag == "Player") { if (isIdle) { Vector3 lclDirection = (collider.transform.position + Vector3.up) - transform.position; RaycastHit lclHitInfo; Debug.DrawRay(transform.position, lclDirection); if (Physics.Raycast(transform.position, lclDirection, out lclHitInfo)) { if (lclHitInfo.collider.gameObject.tag == collider.tag) { Debug.DrawRay(transform.position, lclDirection, Color.red, 1f); StartChasing(collider.gameObject); } } } else { targetContact = true; Player playerscript = ChaseTarget.GetComponent <Player>(); playerscript.zombieTouchCount++; DamageTarget(); } } else if (collider.tag == "Human") { if (isIdle) { Vector3 lclDirection = (collider.transform.position) - transform.position; RaycastHit lclHitInfo; Debug.DrawRay(transform.position, lclDirection, Color.white, 5f); if (Physics.Raycast(transform.position, lclDirection, out lclHitInfo)) { if (lclHitInfo.collider.gameObject.tag == collider.tag) { Debug.DrawRay(transform.position, lclDirection, Color.red, 1f); StartChasing(collider.gameObject); } } } else { targetContact = true; HumanBehaviour humanscript = ChaseTarget.GetComponent <HumanBehaviour>(); humanscript.zombieTouchCount++; DamageTarget(); Debug.Log("Damage zombie target (human)"); } } }
void DamageTarget() { if (ChaseTarget.tag == "Player") { Player playerscript = ChaseTarget.GetComponent <Player>(); playerscript.moveSpeed -= zombieSlowBy * Time.deltaTime; } else if (ChaseTarget.tag == "Human") { HumanBehaviour humanscript = ChaseTarget.GetComponent <HumanBehaviour>(); humanscript.moveSpeed -= 5 * zombieSlowBy * Time.deltaTime; } }
void OnTriggerExit(Collider collider) { if (targetContact) { if (collider.tag == "Player") { Player playerscript = ChaseTarget.GetComponent <Player>(); playerscript.zombieTouchCount--; targetContact = false; } if (collider.tag == "Human") { HumanBehaviour humanscript = ChaseTarget.GetComponent <HumanBehaviour>(); humanscript.zombieTouchCount--; targetContact = false; } } }
void KillZombie() { Debug.Log("Zombie killed by Bullet."); transforming = true; transform.Rotate(new Vector3(90, 0, 0)); //Fall on floor transform.position += new Vector3(0, -1, 0); gameObject.GetComponent <CharacterController>().enabled = false; //Disable physics gameObject.tag = "DeadZombie"; AudioSource.PlayClipAtPoint(zombieDeath[zombieDeathIndex], transform.position); gameManager.zombieCount--; if (targetContact && ChaseTarget.tag == "Player") { Player playerscript = ChaseTarget.GetComponent <Player>(); playerscript.zombieTouchCount--; targetContact = false; } else if (targetContact && ChaseTarget.tag == "Human") { HumanBehaviour humanscript = ChaseTarget.GetComponent <HumanBehaviour>(); humanscript.zombieTouchCount--; targetContact = false; } }
// Start is called before the first frame update void OnEnable() { theHuman = transform.parent.gameObject; theHumanBehaviour = theHuman.GetComponent <HumanBehaviour>(); }
override public void Start() { obstacle = Utility.LayerMaskToInt(obstacle); h = GetComponent <HumanBehaviour>(); }
//private GameObject CreatePiece_Human(GamePiece piece,Color colour) private GameObject CreatePiece_Human(GamePiece piece, HumanBehaviour.HUMAN_TYPE type) { GameObject visualPiece; if(type == HumanBehaviour.HUMAN_TYPE.HUMAN_TYPE_NORMAL) visualPiece = (GameObject)Instantiate(Piece); else// Elite visualPiece = (GameObject)Instantiate(Piece_Elite); visualPiece.transform.position = GetWorldCoordinates(piece.X, piece.Y, 0f); //var mat = new Material(Shader.Find(" Glossy")) {color = colour}; //visualPiece.renderer.material = mat; var pb = (HumanBehaviour)visualPiece.GetComponent("HumanBehaviour"); pb.Piece = piece; return visualPiece; }
// Update is called once per frame void Update() { /* * STATES ARE : * WANDER * ALERT * FULL * * */ timer += Time.deltaTime; // Debug.Log("Shortest distance is " + shortestDistance); // WANDER STATE --------- WANDER STATE --------- WANDER STATE --------- WANDER STATE --------- WANDER STATE ---------WANDER STATE ---------WANDER STATE --------- if (zombieState == "Wander") { zombieAnim.SetBool("IsAlert", false); zombieAnim.SetBool("IsWandering", true); agent.speed = 3.5f; shortestDistance = 500f; if (timer >= wanderTimer) { Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1); agent.SetDestination(newPos); timer = 0; } } // ALERT STATE ------------ // ALERT STATE ------------ // ALERT STATE ------------ // ALERT STATE ------------ // ALERT STATE ------------ // ALERT STATE ------------ // ALERT STATE ------------ if (zombieState == "Alert") { zombieAnim.SetBool("IsWandering", false); zombieAnim.SetBool("IsAlert", true); agent.speed = 10f; if (myList.Count == 0) { zombieState = "Wander"; //return; } //foreach(GameObject i in myList) for (int i = 0; i < myList.Count; i++) { GameObject target = myList[i]; if (myList[i] != null) { // float distance = Vector3.Distance(this.gameObject.transform.position, i.transform.position); float distance = Vector3.Distance(this.gameObject.transform.position, target.transform.position); if (distance < shortestDistance) { shortestDistance = distance; // currentTarget = i; currentTarget = target; //; } } else { zombieState = "Wander"; } } if (currentTarget != null) { Vector3 newPos = currentTarget.transform.position; agent.SetDestination(newPos); HumanBehaviour theHumanBehaviour = currentTarget.GetComponent <HumanBehaviour>(); // float distance = Vector3.Distance(this.gameObject.transform.position, currentTarget.transform.position); if (distance < deathDistance) { if (theHumanBehaviour.isDead == false) { zombieState = "Full"; currentTarget.GetComponent <HumanBehaviour>().humanState = "Dead"; theHumanBehaviour.humanState = "Dead"; Debug.Log("Death to all humans");//Code to kill humans myList.Remove(currentTarget); } } } } if (zombieState == "Full") { myList.Clear(); currentTarget = null; Debug.Log("I am Full"); Invoke("ResetWander", 5f); } }