void SetWispStateToWhite()
 {
     curState       = WispState.WHITE;
     wispAura.color = Color.white;
     anim.SetBool("Fire", false);
     anim.SetBool("Electricity", false);
     wispAura.enabled = true;
     SpriteMask[] theSpriteMasks = FindObjectsOfType <SpriteMask>();
     foreach (SpriteMask sm in theSpriteMasks)
     {
         sm.enabled = true;
     }
 }
 // Use this for initialization
 void Start()
 {
     circ           = GetComponent <CircleCollider2D>();
     curState       = WispState.WHITE;
     Cursor.visible = false;
     //Set the GameObjects's Color quickly to a set Color(blue)
     SpriteRenderer[] child_sprite = GetComponentsInChildren <SpriteRenderer>();
     foreach (SpriteRenderer sr in child_sprite)
     {
         if (sr.tag == "wispAura")
         {
             wispAura = sr;
         }
     }
     anim = GetComponent <Animator>();
 }
    //for the wisp
    //other is the candle
    private void OnTriggerEnter2D(Collider2D other)
    {
        //if colliding with the candle
        switch (other.tag)
        {
        case "srcFire":
            if (curState != WispState.FIRE)
            {
                GameObject instanceSound = Instantiate(toFireSound, transform.position, Quaternion.identity);
                Destroy(instanceSound, 3.0f);
            }
            curState       = WispState.FIRE;
            wispAura.color = Color.yellow;
            anim.SetBool("Electricity", false);
            anim.SetBool("Fire", true);
            //wispAura.enabled = false;
            SpriteMask[] theSpriteMasks = FindObjectsOfType <SpriteMask>();
            foreach (SpriteMask sm in theSpriteMasks)
            {
                sm.enabled = false;
            }
            break;

        case "srcElectric":
            if (curState != WispState.ELECTRIC)
            {
                GameObject instanceSound = Instantiate(toElectricSound, transform.position, Quaternion.identity);
                Destroy(instanceSound, 3.0f);
            }
            curState       = WispState.ELECTRIC;
            wispAura.color = Color.cyan;
            anim.SetBool("Electricity", true);
            anim.SetBool("Fire", false);
            SpriteMask[] theSpriteMasks2 = FindObjectsOfType <SpriteMask>();
            foreach (SpriteMask sm in theSpriteMasks2)
            {
                sm.enabled = false;
            }
            break;

            /*case "srcWater":
             * curState = WispState.WATER;
             * wispAura.color = Color.blue;
             * break;*/
            /*case "destWater":
             * if (curState == WispState.WATER)
             * {
             * Debug.Log("destroy");
             * Destroy(other.gameObject);
             * curState = WispState.ELECTRIC;
             * }
             * break;*/
            /*case "destFire":
             *      if (curState == WispState.FIRE)
             *      {
             *
             * GameObject instanceSound = Instantiate(fireOutSound, transform.position, Quaternion.identity);
             *
             * curState = WispState.WHITE;
             *              other.GetComponent<Box>().BurnBox();
             * SetWispStateToWhite();
             *      }
             *      break;*/
            /*case "destElectric":
             * if (curState == WispState.ELECTRIC)
             * {
             * other.gameObject.GetComponent<Fuseboc>().flipping=true;
             * SetWispStateToWhite();
             * test = false;
             * }
             * break;*/
            //add more test cases here

            /*case "destCandle":
             *      if (curState == WispState.FIRE)
             *      {
             *              other.GetComponent<Candle>().TryActivate();
             *      }
             *      break;*/
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        Vector3 pos = transform.position;

        if (m_State == WispState.Spawned)
        {
            if (transform.position.y > 3f)
            {
                m_State = WispState.Dance;
            }
            m_Velocity     = 0.99f * m_Velocity + 0.01f * Vector3.up * speed;
            m_Direction    = m_Velocity.normalized;
            m_CurrentSpeed = m_Velocity.magnitude;
        }
        else if (m_State == WispState.Dance)
        {
            if (Time.time - m_SpawnTime > m_Params.timeToGo)
            {
                m_State = WispState.Ascent;
            }
            Vector3 ownerPos  = m_ProjectileBase.owner.transform.position;
            Vector3 centerDir = Vector3.Normalize(ownerPos - pos);
            Vector3 rightDir  = Vector3.Cross(centerDir, Vector3.up);
            if (Vector3.Distance(pos, ownerPos) > 2)
            {
                m_Direction = m_Momentum * m_Direction + m_Gravity * centerDir + m_Forward * rightDir + m_Up * Vector3.up;
                m_Direction = m_Direction.normalized;
                if (m_CurrentSpeed < maxSpeed)
                {
                    m_CurrentSpeed += 0.005f;
                }
            }
            m_Velocity = m_Direction * m_CurrentSpeed;
        }
        else if (m_State == WispState.Ascent)
        {
            if (pos.y > m_Params.highEnough)
            {
                m_ChaseStart = Time.time;
                m_State      = WispState.Chase;
            }
            m_Direction = Vector3.Normalize(0.99f * m_Direction + 0.01f * Vector3.up * speed);
            if (m_CurrentSpeed < maxSpeed)
            {
                m_CurrentSpeed += 0.005f;
            }
            m_Velocity = m_Direction * m_CurrentSpeed;
        }
        else if (m_State == WispState.Chase)
        {
            Tuple <Vector3, bool> result = somethingUnder();
            if (result.Item2 && Time.time - m_ChaseStart > m_Params.minTimeBeforeFall)
            {
                m_State      = WispState.StarFallEntrance;
                m_FallTarget = result.Item1;
            }
            if (m_CurrentSpeed > searchSpeed)
            {
                m_CurrentSpeed -= 0.01f;
            }
            Vector3 targetDirection = Vector3.Normalize(targetCharacter.position - pos);
            m_Direction   = 0.9f * m_Direction + 0.1f * targetDirection;
            m_Direction.y = 0f;
            m_Direction   = m_Direction.normalized;
            m_Velocity    = m_Direction * m_CurrentSpeed;
        }
        else if (m_State == WispState.StarFallEntrance)
        {
            m_State     = WispState.StarFall;
            m_Direction = Vector3.Normalize(m_FallTarget - pos);
            m_Velocity  = m_CurrentSpeed * m_Direction;
        }
        else if (m_State == WispState.StarFall)
        {
            if (m_CurrentSpeed < starFallSpeed)
            {
                m_CurrentSpeed += 1f;
                m_Velocity      = m_CurrentSpeed * m_Direction;
            }
            CheckHit();
        }

        // JitterRotation();
        JitterDirection();
        transform.position += m_Velocity * Time.deltaTime;
        // transform.RotateAround(pos, transform.up, Time.deltaTime *m_RotationSpeed* pos.y);
    }