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);
        }
    }
예제 #2
0
 private void CreateBehavior(BehaviorScript b)
 {
     if (b.behaviorScript != null && b.behaviorScript.GetClass().IsSubclassOf(typeof(IBehavior)))
     {
         b.behavior = (IBehavior)ScriptableObject.CreateInstance(b.behaviorScript.GetClass());
     }
 }
예제 #3
0
 // 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);
     }
 }
예제 #4
0
    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);
        }
    }
예제 #5
0
    public void ExecuteScript(BehaviorScript script, bool loop)
    {
        isExecuting = true;
        isLooping   = loop;

        currentBehaviorIndex = 0;
        nextBehaviorTime     = 0;
    }
예제 #6
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);
 }
예제 #8
0
    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;
    }
예제 #9
0
    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);
        }
    }
예제 #10
0
    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();
    }
예제 #11
0
 public void ExecuteScript(BehaviorScript script)
 {
     ExecuteScript(script, false);
 }
예제 #12
0
 // function will create a instance of the class for the behaviour
 private void CreateBehavior(BehaviorScript b)
 {
 }
예제 #13
0
 public void ExecutingScript(BehaviorScript script, bool loop)
 {
     executor.ExecuteScript(script, loop);
 }