Exemple #1
0
    protected void Trigger()
    {
        if (isTriggered)
        {
            return;
        }

        GameObject    controlledObj      = skill.manager.currentObject;
        BoxCollider2D controlledCollider = controlledObj.GetComponent <BoxCollider2D>() as BoxCollider2D;

        if (!collider.IsTouching(controlledCollider))
        {
            return;
        }

        spriteRenderer.sprite = triggeredSprite;
        if (target != null)
        {
            target.SendMessage("startMoving");
        }
        isTriggered = true;
        SFXUtils.PlayOnce(SFXUtils.Clips.Switch, 1.0f);

        if (controlledObj != player)
        {
            skill.takeBackControll();
        }
    }
Exemple #2
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.layer == 8 &&
         collision.transform.position.y < initialY - 1.5)
     {
         SFXUtils.PlayOnce(SFXUtils.Clips.WoodenBox, 1.0f);
     }
 }
    IEnumerator moving()
    {
        AudioSource audioMoving = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
        AudioSource audioOff    = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;

        audioMoving.clip = SFXUtils.GetClip(SFXUtils.Clips.ElectricMotor);
        audioOff.clip    = SFXUtils.GetClip(SFXUtils.Clips.ElectricMotorOff);

        audioMoving.volume = 1;
        audioMoving.loop   = true;
        audioMoving.Play();
        transform.position = originPos;
        float currentTime     = Time.time;
        bool  audioOffStarted = false;
        // How much early should the "off" sound start playing, in seconds
        const float Anticipation = 1.0f;

        while (Time.time - currentTime <= m_MovingTime)
        {
            float r = (Time.time - currentTime) / m_MovingTime;
            if (easeOut)
            {
                r = Mathf.Sin(r * Mathf.PI / 2);
            }
            transform.position = Vector3.Lerp(originPos, targetPos, r);
            // Audio envelope
            if (Time.time - currentTime >= m_MovingTime - Anticipation)
            {
                // Check for the start of the tail sound
                if (!audioOffStarted)
                {
                    audioOffStarted = true;
                    audioOff.Play();
                }
                audioMoving.volume = (m_MovingTime - (Time.time - currentTime)) / Anticipation;
                audioOff.volume    = 1 - audioMoving.volume;
            }
            else
            {
                audioMoving.volume = Mathf.Min(1, (Time.time - currentTime) / 0.1f);
            }
            yield return(new WaitForSeconds(0));
        }
        audioOff.volume = 1;
        audioMoving.Stop();
        transform.position = targetPos;
        yield return(null);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Z) && gameObject.GetComponent <MoveController>().grounded)
        {
            if (GetComponent <Player>().controlled)
            {
                if (controlTarget != null)
                {
                    DPtimer += Time.deltaTime;
                }
                else
                {
                    DPtimer = 0;
                }
            }
            else
            {
                DPtimer += Time.deltaTime;
            }


            if (DPtimer >= skillDP)
            {
                if (GetComponent <Player>().controlled)
                {
                    useControllSkill();
                    DPtimer = 0;
                    SFXUtils.PlayOnce(SFXUtils.Clips.Control, 1.0f);
                }
                else
                {
                    takeBackControll();
                    DPtimer = 0;
                    SFXUtils.PlayOnce(SFXUtils.Clips.Discontrol, 1.0f);
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.X))           // TODO: Change this
        {
            switchTriggerEvent.Invoke();
        }
        else
        {
            DPtimer = 0;
        }
        //! only for test
        //manager.showSkillBar(DPtimer / skillDP);
    }
    IEnumerator Break()
    {
        yield return(new WaitForSeconds(delay));

        SpriteRenderer renderer = sprite.GetComponent <SpriteRenderer>() as SpriteRenderer;

        renderer.enabled = false;
        sprite1.SetActive(true);
        sprite2.SetActive(true);
        gameObject.SetActive(false);
        ParticleSystem sys = sprite.GetComponent <ParticleSystem>() as ParticleSystem;

        if (sys != null)
        {
            sys.Play();
        }
        SFXUtils.PlayOnce(SFXUtils.Clips.Brickbreaking, 1.0f);
    }
Exemple #6
0
 void Update()
 {
     if (controller.grounded && Mathf.Abs(body.velocity.x) >= 0.01)
     {
         timeSinceLastStep += Time.deltaTime;
         if (timeSinceLastStep >= stepInterval)
         {
             timeSinceLastStep = 0;
             string tag = controller.groundTag;
             if (isWorker)
             {
                 float distance = Vector3.Distance(body.transform.position, Camera.main.transform.position);
                 float volume   = Mathf.Clamp((25 - distance) / (25 - 15) * 0.8f, 0, 0.8f) * overallVolume;
                 if (tag == "MetalPlatform")
                 {
                     SFXUtils.PlayRandomOnce(SFXUtils.Clips.WalkMetal1, SFXUtils.Clips.WalkMetal6, volume);
                 }
                 else
                 {
                     SFXUtils.PlayRandomOnce(SFXUtils.Clips.WalkPatrol1, SFXUtils.Clips.WalkPatrol6, volume);
                 }
             }
             else
             {
                 if (tag == "WoodenBox")
                 {
                     SFXUtils.PlayRandomOnce(SFXUtils.Clips.WalkWood1, SFXUtils.Clips.WalkWood6, overallVolume);
                 }
                 else if (tag == "MetalPlatform")
                 {
                     SFXUtils.PlayRandomOnce(SFXUtils.Clips.WalkMetal1, SFXUtils.Clips.WalkMetal6, overallVolume);
                 }
                 else
                 {
                     SFXUtils.PlayRandomOnce(SFXUtils.Clips.WalkHard1, SFXUtils.Clips.WalkHard6, overallVolume);
                 }
             }
         }
     }
     else
     {
         timeSinceLastStep = stepInterval / 2;
     }
 }
    void Start()
    {
        triggerTime = -1;
        if (duration == 0)
        {
            duration = 1;
        }
        player   = GameObject.FindGameObjectsWithTag("Player")[0];
        objs     = GameObject.FindGameObjectsWithTag("Enermy");
        collider = gameObject.GetComponent <PolygonCollider2D>() as PolygonCollider2D;
        trans    = gameObject.GetComponent <Transform>() as Transform;
        if (player == null || collider == null || trans == null)
        {
            return;
        }

        audioSrc      = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
        audioSrc.clip = SFXUtils.GetClip(SFXUtils.Clips.Pulley);
    }
    public void ControlMove()
    {
        if (!canMove)
        {
            return;
        }

        float horizontal = Input.GetAxis("Horizontal");

        moveVelocity = horizontal * moveSpeed;

        if (horizontal != 0)
        {
            transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * (horizontal < 0 ? -1 : 1), transform.localScale.y, transform.localScale.z);
            if (animator != null)
            {
                animator.SetBool("Moving", true);
            }
        }
        else
        {
            if (animator != null)
            {
                animator.SetBool("Moving", false);
            }
        }

        Vector2 velocity = GetComponent <Rigidbody2D>().velocity;

        velocity.x = Mathf.SmoothDamp(velocity.x, moveVelocity, ref dampVelocity, dampTime);
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) && grounded)
        {
            velocity.y = jumpHeight * 1.4f;
            if (animator != null)
            {
                animator.SetTrigger("Jump");
            }
            SFXUtils.PlayOnce(SFXUtils.Clips.Jump, 1.0f);
        }
        GetComponent <Rigidbody2D>().velocity = velocity;
    }
    void FixedUpdate()
    {
        Rigidbody2D body = GetComponent <Rigidbody2D>();

        if (Mathf.Abs(body.velocity.y) > jumpHeight * 1.4f * 0.55f)
        {
            body.gravityScale = 2.0f;
        }
        //if (body.velocity.y != 0) Debug.Log(body.velocity.y);
        if (!canMove)
        {
            body.velocity = new Vector2(0, body.velocity.y);
        }
        Collider2D collider = Physics2D.Raycast(transform.position, Vector2.down, 0.1f, WhatIsGround).collider;

        if (collider != null)
        {
            if (!grounded)
            {
                if (firstTimeGround)
                {
                    firstTimeGround = false;
                }
                else
                {
                    SFXUtils.PlayOnce(SFXUtils.Clips.Fall, 1.0f);
                }
            }
            grounded  = true;
            groundTag = collider.gameObject.tag;
        }
        else
        {
            grounded = false;
        }
        if (animator != null)
        {
            animator.SetBool("Hovering", !grounded);
        }
    }
Exemple #10
0
    // Update is called once per frame
    void Update()
    {
        if (controlled)
        {
            playerMove.canMove = true;
            playerMove.ControlMove();
        }
        else
        {
            playerMove.canMove = false;
        }

        var hit = Physics2D.Raycast(face.position,
                                    new Vector2(Mathf.Cos(77.71f * Mathf.Deg2Rad), Mathf.Sin(77.71f * Mathf.Deg2Rad)),
                                    Mathf.Infinity,
                                    LayerMask.GetMask("Floor") | LayerMask.GetMask("Hole") | LayerMask.GetMask("Shelter"));

        if (hit.collider == null || LayerMask.LayerToName(hit.transform.gameObject.layer) == "Hole")
        {
            gameManager.GameOver();
            SFXUtils.PlayOnce(SFXUtils.Clips.Burnout, 1.0f);
        }
    }