示例#1
0
 public override void IsHit()
 {
     base.IsHit();
     if (_state == EnemyPlaneState.STATE_PATROL) {
         State = EnemyPlaneState.STATE_EVADE;
         _SetEvadeBearing();
     }
     _healthBar.value = health;
     if (_healthBar.value < 2.0f * _healthBar.maxValue / 3.0f) {
         if (_healthBar.value < _healthBar.maxValue / 3.0f) {
             _healthFill.color = new Color(1.0f, 0.0f, 0.0f, 0.7f);
         }
         else {
             _healthFill.color = new Color(1.0f, 1.0f, 0.0f, 0.7f);
         }
     }
     if (health == 0) {
         GameObject theExplosion = Instantiate(explodeInst, transform.position, transform.rotation) as GameObject;
         Rigidbody rb = theExplosion.GetComponent<Rigidbody>();
         rb.velocity = transform.forward * speed;
         smoke.transform.SetParent(theExplosion.transform, false);
         //smoke.loop = false;
         theExplosion.SetActive(true);
         if (pitch < 0)
         {
             rb.AddRelativeTorque( new Vector3(0, 0, -180.0f));
         }
         else
         {
             rb.AddRelativeTorque( new Vector3(0, 0, 180.0f));
         }
         Transform modelMesh = model.FindChild("Mesh");
         modelMesh.SetParent(theExplosion.transform, false);
         Destroy (gameObject);
     }
 }
示例#2
0
 private void _CheckChangeInState()
 {
     if (_CanSeePlayer())
     {
         timeSinceSeeingPlayer = 0.0f;
         if (State != EnemyPlaneState.STATE_ATTACK)
         {
             State = EnemyPlaneState.STATE_ATTACK;
         }
     }
     else
     {
         timeSinceSeeingPlayer += Time.deltaTime;
         if (timeSinceSeeingPlayer > 0.5f && _state == EnemyPlaneState.STATE_ATTACK)
         {
             _CheckNextWayPoint();
             State = EnemyPlaneState.STATE_PATROL;
         }
     }
 }
示例#3
0
    // Use this for initialization
    protected new void Start()
    {
        model = Instantiate(modelPrefab, transform.position, transform.rotation) as Transform;
        model.SetParent(transform, true);
        guiCanvas = GameObject.Find ("HUD");
        base.Start();
        _state = EnemyPlaneState.STATE_PATROL;
        _healthBar = transform.Find("Health").GetComponent<Slider>();
        _healthBar.transform.SetParent(guiCanvas.transform);
        _healthFill = _healthBar.GetComponentsInChildren<UnityEngine.UI.Image>()
            .FirstOrDefault(t => t.name == "Fill");
        //TODO: Find front of colliders
        frontOfPlane = 9.76f;
        //TODO: Read the waypoints and start position from a file or the scene.
        _wayPoints = new List<Vector2>();
        addWayPoint(0.0f, 4.0f);
        addWayPoint(-1.0f, 5.0f);
        addWayPoint(-4.0f, 5.0f);
        addWayPoint(-5.0f, 4.0f);
        addWayPoint(-5.0f, 1.0f);
        addWayPoint(-4.0f, 0.0f);
        addWayPoint(2.0f, 0.0f);
        addWayPoint(3.0f, -1.0f);
        addWayPoint(3.0f, -2.0f);
        addWayPoint(2.0f, -3.0f);
        addWayPoint(1.0f, -3.0f);
        addWayPoint(0.0f, -2.0f);

        _player = GameObject.Find("PlayerPlane");
        if (_player != null)
        {
            _playerPlane = _player.GetComponent<PlayerPlaneScript>();
            _playerPlane.addEnemy(this);
            _arrow = transform.FindChild("Arrow").gameObject;
            _arrow.transform.SetParent(null);
        }
    }
示例#4
0
    private void UpdateDirection_Evade()
    {
        float diffAngle = _evadeHeadingDiff;
        //Debug.Log("Curr " + currentAngle.ToString() + " req " + requiredAngle.ToString());
        float reqPitch = Mathf.Clamp(1.0f * -diffAngle / Mathf.PI, -1.0f, 1.0f);
        //Debug.Log("Pitch " + pitch.ToString() + " Req " + reqPitch.ToString());

        if (reqPitch < (pitch - 5.0f * Time.deltaTime))
            pitch -= Time.deltaTime * 4.0f;
        if (reqPitch > (pitch + 5.0f * Time.deltaTime))
            pitch += Time.deltaTime * 4.0f;
        pitch = Mathf.Clamp (pitch, -0.5f, 0.5f);
        float prevDiff = _evadeHeadingDiff;
        //		_evadeHeadingDiff += (pitch * Time.deltaTime * 8.0f / timeForCircle);
        _evadeTime -= Time.deltaTime;
        if (Mathf.Sign (prevDiff) != Mathf.Sign (_evadeHeadingDiff) || _evadeTime <= 0.0f)
        {
            State = EnemyPlaneState.STATE_PATROL;
        }
    }
示例#5
0
 public void UnregisterPlayer(PlayerPlaneScript thePlayer)
 {
     _playerPlane = null;
     Destroy (_arrow);
     _state = EnemyPlaneState.STATE_PATROL;
 }