void OnControllerColliderHit(ControllerColliderHit hit) { Collider collider = hit.collider; if (collider.gameObject.CompareTag("Agent")) { AudioSource.PlayClipAtPoint(getCaught, gameObject.transform.position); Debug.Log("Player collided with Agent"); BehaviorScript agentScript = collider.gameObject.GetComponent <BehaviorScript>(); Vector3 location = agentScript.transform.position; if (checkHidingLocation(location)) { agentScript.frozen = false; } else { agentScript.frozen = true; } } else { Debug.Log("Player collided with " + collider.tag); } }
private void CreateBehavior(BehaviorScript b) { if (b.behaviorScript != null && b.behaviorScript.GetClass().IsSubclassOf(typeof(IBehavior))) { b.behavior = (IBehavior)ScriptableObject.CreateInstance(b.behaviorScript.GetClass()); } }
// will get the children and will execute it's behaviour and set the child to the current behaviour if it's true public bool GetChildren(out BehaviorScript currentBehavior, GameObject o) { if (!checkAll) { foreach (BehaviorScript child in children) { if (child.behavior == null) { CreateBehavior(child); } if (child.behavior != null && child.behavior.Execute(o)) { currentBehavior = child; child.parent = this; return(true); } } if (this.parent != null) { currentBehavior = this.parent; } else { currentBehavior = null; } return(false); } else { foreach (BehaviorScript child in children) { if (!child.ignore) { if (child.behavior != null && !child.behavior.Execute(o)) { child.ignore = true; if (this.parent != null) { currentBehavior = this.parent; } else { currentBehavior = null; } return(false); } } child.ignore = false; } if (this.parent != null) { currentBehavior = this.parent; } else { currentBehavior = null; } return(true); } }
void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; if (collider.CompareTag("Agent")) { AudioSource.PlayClipAtPoint(saveKnell, gameObject.transform.position); Debug.Log("Agent collided with Agent"); BehaviorScript resc = collider.gameObject.GetComponent <BehaviorScript>(); resc.frozen = false; GameObject[] AGENT = GameObject.FindGameObjectsWithTag("Agent"); for (int i = 0; i < gscript.numAgents; i++) { if (i != resc.agentID) { BehaviorScript currentAgent = AGENT[(int)(gscript.agentData[i].agentID)].GetComponent <BehaviorScript>(); if (currentAgent.rescueMission == true) { currentAgent.rescueMission = false; } } } } else { Debug.Log("Agent collided with " + collider.tag); } }
public void ExecuteScript(BehaviorScript script, bool loop) { isExecuting = true; isLooping = loop; currentBehaviorIndex = 0; nextBehaviorTime = 0; }
void Update() { if (currentBehavior != null) { currentBehavior.GetChildren(out currentBehavior); } else { currentBehavior = behaviorStarter; } }
bool allFrozen() { for (int i = 0; i < gscript.numAgents; i++) { BehaviorScript currentAgent = gscript.agents[i].GetComponent <BehaviorScript>(); if (currentAgent.frozen == false) { return(false); } } return(true); }
public void effect() { AudioSource.PlayClipAtPoint(shootKnell, gameObject.transform.position); Instantiate(effectExplosion, gameObject.transform.position, Quaternion.AngleAxis(-90, Vector3.right)); BehaviorScript changeVel = gameObject.GetComponent <BehaviorScript>(); float [] velocity = gscript.agentData[changeVel.agentID].aVel; if ((velocity[0] > 0.0f) && (velocity[1] > 0.0f) && (velocity[2] > 0.0f)) { velocity[0] -= 3.0f; velocity[2] -= 3.0f; } gscript.agentData[changeVel.agentID].aVel = velocity; }
void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; if (collider.CompareTag("Agent")) { BehaviorScript Ag = collider.gameObject.GetComponent <BehaviorScript>(); Ag.effect(); Destroy(gameObject); } else { Debug.Log("Collided with " + collider.tag); Destroy(gameObject); } }
public void clearMap() { for (int i = 0; i < obstacleCount; i++) { Destroy(GameObject.Find("Mushroom" + i)); } ClearObstacles(); obstacleCount = 0; for (int i = 0; i < HPList.Count; i++) { Destroy(HPList[i]); } BehaviorScript bs0 = GameObject.Find("Agent0").GetComponent <BehaviorScript>(); BehaviorScript bs1 = GameObject.Find("Agent1").GetComponent <BehaviorScript>(); bs0.target = GameObject.Find("Target"); bs1.target = GameObject.Find("Target"); HPList.Clear(); }
public void ExecuteScript(BehaviorScript script) { ExecuteScript(script, false); }
// function will create a instance of the class for the behaviour private void CreateBehavior(BehaviorScript b) { }
public void ExecutingScript(BehaviorScript script, bool loop) { executor.ExecuteScript(script, loop); }