void onRespawnWaypoint(AIEventArgs e)
 {
     Instantiate(respawnEffect, e.position, e.rotation);
     //Example:
     //message = e.name + " was respawned at '" + e.position.x + ";" + e.position.x + ";" + e.position.x +"'.";
     //StartCoroutine(ShowMessage(message, 1));
 }
示例#2
0
    IEnumerator CharacterHit()
    {
        if (hitAnimation != "")
        {
            isHit = true;
            if (crossFadeAnimations)
            {
                GetComponent <Animation>().CrossFade(hitAnimation);
            }
            else
            {
                GetComponent <Animation>().Play(hitAnimation);
            }
            if (playSound)
            {
                hitSound.Play();
            }
            yield return(new WaitForSeconds(0.4f));

            isHit = false;
        }

        if (onHit != null)
        {
            AIEventArgs e = new AIEventArgs();
            e.name     = gameObject.name;
            e.health   = health;
            e.position = gameObject.transform.position;
            e.rotation = gameObject.transform.rotation;
            e.tag      = gameObject.tag;
            onHit(e);
        }
    }
示例#3
0
 void OnDestroy()
 {
     if (onIsDead != null && isAlive == false)
     {
         AIEventArgs e = new AIEventArgs();
         e.name     = gameObject.name;
         e.health   = health;
         e.position = gameObject.transform.position;
         e.rotation = gameObject.transform.rotation;
         e.tag      = gameObject.tag;
         onIsDead(e);
     }
 }
示例#4
0
    void onIsDying(AIEventArgs e)
    {
        message = e.name + " is Dying at position " + e.position + ".";
        Debug.Log(message);
        StartCoroutine(ShowMessage(message, 1));

        if (e.name != "soldier") //2011-05-28-1
        {                        //2011-05-28-1
            GameObject smokeObject = Instantiate(smoke, e.position, e.rotation) as GameObject;
            Destroy(smokeObject, 4);
        }                       //2011-05-28-1

        destroyedCounter++;
    }
    void onIsDying(AIEventArgs e)
    {
        message = e.name + " is Dying at position " + e.position + ".";
        Debug.Log(message);
        StartCoroutine(ShowMessage(message,1));

        if (e.name != "soldier")//2011-05-28-1
        {                       //2011-05-28-1
            GameObject smokeObject = Instantiate(smoke, e.position, e.rotation) as GameObject;
            Destroy(smokeObject, 4);
        }                       //2011-05-28-1

        destroyedCounter++;
    }
示例#6
0
    IEnumerator CharacterDie()
    {
        if (!isDead)
        {
            isDead  = true;
            isAlive = false;
            //Debug.Log("Play die");
            if (dieAnimation != "")
            {
                if (crossFadeAnimations)
                {
                    GetComponent <Animation>().CrossFade(dieAnimation);
                }
                else
                {
                    GetComponent <Animation>().Play(dieAnimation);
                }
            }

            if (playSound)
            {
                dieSound.Play();
            }

            yield return(new WaitForSeconds(0.4f));

            if (deathDelayTime == 0)
            {
                Destroy(this.gameObject);
            }
            else if (deathDelayTime > 0)
            {
                Destroy(this.gameObject, deathDelayTime);
            }

            if (onIsDying != null)
            {
                AIEventArgs e = new AIEventArgs();
                e.name     = gameObject.name;
                e.health   = health;
                e.position = gameObject.transform.position;
                e.rotation = gameObject.transform.rotation;
                e.tag      = gameObject.tag;
                onIsDying(e);
            }
        }
    }
    public void NextWaypoint()
    {
        AIWaypoint aiWaypoint;
        aiWaypoint = waypoints[currentWaypoint].GetComponent("AIWaypoint") as AIWaypoint;

        if (aiWaypoint != null)
        {
            m_maxSpeed = aiWaypoint.speed;
        }
        else
        {
            m_maxSpeed = m_calcMaxSpeed;
        }

        currentWaypoint++;

        aiRespawnControllerScript.lastTimeToReachNextWP = 0;

        if (currentWaypoint >= waypoints.Count)
        {
            //currentWaypoint = waypoints.Count -1; //2011-12-27
            //fire event BEGIN
            if (onLastWaypoint != null)
            {
                AIEventArgs e = new AIEventArgs();
                e.name = gameObject.name;
                e.currentWaypointIndex = currentWaypoint;
                e.currentWaypointName = waypoints[currentWaypoint -1].name; //2011-12-27-B
                //e.currentWaypointName = waypoints[currentWaypoint].name;	//2011-12-27-E
                e.position = gameObject.transform.position;
                e.rotation = gameObject.transform.rotation;
                e.tag = gameObject.tag;
                onLastWaypoint(e);
            }
            //fire event END
        }
    }
示例#8
0
    void AiSteering()
    {
        if (currentWaypoint < waypoints.Count){
            Vector3 target  = waypoints[currentWaypoint].position;
            Vector3 moveDirection  = target - transform.position;
            Vector3 localTarget = transform.InverseTransformPoint(waypoints[currentWaypoint].position);

            if (!useObstacleAvoidance)
            {
                targetAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg;
            }
            else
            {
                //ObstacleAvoidance
                currentAngle = ObstacleAvoidanceSteering();
            }
            //iaSteerAngle = Mathf.Clamp(targetAngle, -1, 1);

            if (currentAngle < targetAngle)
            {
                currentAngle = currentAngle + (Time.deltaTime * steeringSpeed);
                if (currentAngle > targetAngle)
                {
                    currentAngle = targetAngle;
                }
            }
            else if (currentAngle > targetAngle)
            {
                currentAngle = currentAngle - (Time.deltaTime * steeringSpeed);
                if (currentAngle < targetAngle)
                {
                    currentAngle = targetAngle;
                }
            }

            //je hoeher die Geschwindigkeit,  desto geringer der maximale Einschlagwinkel.
            float aiCalculationMaxSpeed = calcMaxSpeed;
            //float speedProcent = currentSpeed / maxSpeed;
            float speedProcent = currentSpeed / aiCalculationMaxSpeed;
            speedProcent = Mathf.Clamp(speedProcent, 0, 1);
            float speedControlledMaxSteerAngle;
            speedControlledMaxSteerAngle = steerAngle - ((steerAngle - hsSteerAngle) * speedProcent);

            aiSteerAngle = Mathf.Clamp(currentAngle, (-1) * speedControlledMaxSteerAngle, speedControlledMaxSteerAngle);

            //if (moveDirection.magnitude < 2) {
            if (moveDirection.sqrMagnitude < sqrDistanceToWaypoint)
            {

                //Debug.Log("currentWaypoint: " + currentWaypoint.ToString());
                AIWaypoint aiWaypoint;
                aiWaypoint = waypoints[currentWaypoint].GetComponent("AIWaypoint") as AIWaypoint;
                if (aiWaypoint != null)
                {
                    maxSpeed = aiWaypoint.speed;
                }
                else
                {
                    maxSpeed = calcMaxSpeed;
                }
                currentWaypoint++;

                aiRespawnScript.lastTimeToReachNextWP = 0;

                if (currentWaypoint >= waypoints.Count)
                {
                    //fire event BEGIN
                    if (onLastWaypoint != null)
                    {
                        AIEventArgs e = new AIEventArgs();
                        e.name = gameObject.name;
                        e.currentWaypointIndex = currentWaypoint;
                        e.currentWaypointName = waypoints[currentWaypoint -1].name;
                        e.position = gameObject.transform.position;
                        e.rotation = gameObject.transform.rotation;
                        e.tag = gameObject.tag;
                        onLastWaypoint(e);
                    }
                    //fire event END
                }
            }

        }
        else {

            //if (driveCircleModus)
            if (driveMode == DriveMode.Laps)
            {
                currentWaypoint = 0;
            }
            else
            {
                aiSpeedPedal = 0;
                aiRespawnScript.enabled = false;
            }

        }
    }
示例#9
0
 void OnDestroy()
 {
     if (onIsDead != null && isAlive == false)
     {
         AIEventArgs e = new AIEventArgs();
         e.name = gameObject.name;
         e.health = health;
         e.position = gameObject.transform.position;
         e.rotation = gameObject.transform.rotation;
         e.tag = gameObject.tag;
         onIsDead(e);
     }
 }
示例#10
0
    IEnumerator CharacterHit()
    {
        if (hitAnimation != "")
        {
            isHit = true;
            if (crossFadeAnimations)
            {
                GetComponent<Animation>().CrossFade(hitAnimation);
            }
            else
            {
                GetComponent<Animation>().Play(hitAnimation);
            }
            if (playSound)
            {
                hitSound.Play();
            }
            yield return new WaitForSeconds(0.4f);
            isHit = false;
        }

        if (onHit != null)
        {
            AIEventArgs e = new AIEventArgs ();
            e.name = gameObject.name;
            e.health = health;
            e.position = gameObject.transform.position;
            e.rotation = gameObject.transform.rotation;
            e.tag = gameObject.tag;
            onHit(e);
        }
    }
示例#11
0
    IEnumerator CharacterDie()
    {
        if (!isDead)
        {
            isDead = true;
            isAlive = false;
            //Debug.Log("Play die");
            if (dieAnimation != "")
            {

                if (crossFadeAnimations)
                {
                    GetComponent<Animation>().CrossFade(dieAnimation);
                }
                else
                {
                    GetComponent<Animation>().Play(dieAnimation);
                }

            }

            if (playSound)
            {
                dieSound.Play();
            }

            yield return new WaitForSeconds(0.4f);

            if (deathDelayTime == 0)
            {
                Destroy(this.gameObject);
            }
            else if (deathDelayTime > 0)
            {
                Destroy(this.gameObject, deathDelayTime);
            }

            if (onIsDying != null)
            {
                AIEventArgs e = new AIEventArgs();
                e.name = gameObject.name;
                e.health = health;
                e.position = gameObject.transform.position;
                e.rotation = gameObject.transform.rotation;
                e.tag = gameObject.tag;
                onIsDying(e);
            }
        }
    }
 void onIsDead(AIEventArgs e)
 {
     message = e.name + " is dead.";
     Debug.Log(message);
     StartCoroutine(ShowMessage(message,2));
 }
 void onHit(AIEventArgs e)
 {
     message = e.name + " is be hit. Current health is " + e.health + ".";
     Debug.Log(message);
     StartCoroutine(ShowMessage(message,1));
 }
示例#14
0
    void Respawn()
    {
        int currentWaypoint = aiDriverScript.currentWaypoint;
        if (currentWaypoint == 0)
        {
            currentWaypoint  = waypoints.Count -1;
        }
        else
        {
            currentWaypoint -= 1;
        }
        currentRespawnPoint = waypoints[currentWaypoint];
        transform.position = currentRespawnPoint.position;
        transform.rotation = currentRespawnPoint.rotation;

        aiDriverScript.aiSteerAngle = 0;
        aiDriverScript.currentAngle = 0;

        isStartingRespawn = false;
        lastTimeToReachNextWP = 0;

        //fire event BEGIN
        if (onRespawnWaypoint != null)
        {
            AIEventArgs e = new AIEventArgs();
            e.name = gameObject.name;
            e.currentWaypointIndex = currentWaypoint;
            e.currentWaypointName = waypoints[currentWaypoint].name;
            e.position = gameObject.transform.position;
            e.rotation = gameObject.transform.rotation;
            e.tag = gameObject.tag;
            onRespawnWaypoint(e);
        }
        //fire event END
    }
 void onLastWaypoint(AIEventArgs e)
 {
     //Example:
     //message = e.name + " reached last Waypoint '" + e.currentWaypointName + "' (" + e.currentWaypointIndex +").";
     //StartCoroutine(ShowMessage(message,1));
 }
示例#16
0
 void onHit(AIEventArgs e)
 {
     message = e.name + " is be hit. Current health is " + e.health + ".";
     Debug.Log(message);
     StartCoroutine(ShowMessage(message, 1));
 }
示例#17
0
 void onIsDead(AIEventArgs e)
 {
     message = e.name + " is dead.";
     Debug.Log(message);
     StartCoroutine(ShowMessage(message, 2));
 }
    void Respawn()
    {
        Vector3 startPos;

        StartCoroutine(Freeze(1));

        int currentWaypoint = aiDriverControllerScript.currentWaypoint;
        if (currentWaypoint == 0)
        {
            currentWaypoint  = waypoints.Count -1;
        }
        else
        {
            currentWaypoint -= 1;
        }
        currentRespawnPoint = waypoints[currentWaypoint];
        startPos = currentRespawnPoint.position;
        startPos.y += heightOffset;
        transform.position = startPos;
        transform.rotation = currentRespawnPoint.rotation;

        aiDriverControllerScript.aiSteerAngle = 0;
        aiDriverControllerScript.currentAngle = 0;

        isStartingRespawn = false;
        lastTimeToReachNextWP = 0;

        //fire event BEGIN
        if (onRespawnWaypoint != null)
        {
            AIEventArgs e = new AIEventArgs();
            e.name = gameObject.name;
            e.currentWaypointIndex = currentWaypoint;
            e.currentWaypointName = waypoints[currentWaypoint].name;
            e.position = gameObject.transform.position;
            e.rotation = gameObject.transform.rotation;
            e.tag = gameObject.tag;
            onRespawnWaypoint(e);
        }
        //fire event END
    }