Ejemplo n.º 1
0
        override protected void Update()
        {
            base.Update();

            // Paint.
            if (usePaint && (Time.time - lastSplatterTime > paintTimeout) && groundState.IsTouching() &&
                input != Vector2.zero)
            {
                lastSplatterTime = Time.time;

                if (groundState.raycastDown)
                {
                    splatter.Spawn(groundState.raycastDown.point + Vector2.down * paintPositionOffset, Vector3.down);
                }
                if (groundState.raycastUp)
                {
                    splatter.Spawn(groundState.raycastUp.point + Vector2.up * paintPositionOffset, Vector3.up);
                }
                if (groundState.raycastLeft)
                {
                    splatter.Spawn(groundState.raycastLeft.point + Vector2.left * paintPositionOffset, Vector3.left);
                }
                if (groundState.raycastRight)
                {
                    splatter.Spawn(groundState.raycastRight.point + Vector2.right * paintPositionOffset, Vector3.right);
                }
            }
        }
Ejemplo n.º 2
0
        override protected void Update()
        {
            base.Update();

            if (useSplatter && (Time.time - lastSplatterTime) > paintTimeout && input != Vector3.zero)
            {
                lastSplatterTime = Time.time;
                splatter.Spawn(transform.position + paintPositionOffset);
            }
        }
Ejemplo n.º 3
0
        private IEnumerator HandleBaloonPop(Vector3 pos)
        {
            gameObject.SetActive(false);
            splatter.Spawn(pos);
            if (screenShake != null)
            {
                screenShake.Shake();
            }

            yield return(0);
        }
Ejemplo n.º 4
0
        private void HandleParticleCollision(Vector3 position, Vector3 velocity)
        {
            if (splatterManager != null)
            {
                splatterManager.Spawn(position, velocity.normalized, splatterColor);
            }

            // Screen shake on landing.
            if (screenShake != null)
            {
                screenShake.Shake();
            }
        }
Ejemplo n.º 5
0
        private void Update()
        {
            lineRenderer.SetPosition(0, transform.position);

            Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            mouseWorldPosition.z = 0f;
            Vector2 direction = mouseWorldPosition - transform.position;

            direction.Normalize();

            RaycastHit2D raycastHit = Physics2D.Raycast(transform.position, direction);
            Vector2      pos2d      = (Vector2)transform.position;

            if (raycastHit.collider != null && (raycastHit.point - pos2d).magnitude < lineLength)
            {
                lineRenderer.SetPosition(1, raycastHit.point);
            }
            else
            {
                lineRenderer.SetPosition(1, pos2d + direction * lineLength);
            }

            if (rotateTransform != null)
            {
                var d = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
                rotateTransform.rotation = Quaternion.AngleAxis(Mathf.Atan2(d.y, d.x) * Mathf.Rad2Deg, Vector3.forward);
            }

            bool justClicked = Input.GetMouseButtonDown(0) && !shootWhilePressed;
            bool autoShot    = shootWhilePressed && Input.GetMouseButton(0) && Time.time > (lastShotTime + shootingTimout);

            if (justClicked || autoShot)
            {
                // Apply recoil.
                if (rb != null)
                {
                    rb.AddForce(recoilStrength * direction * -1f, ForceMode2D.Impulse);
                }

                // Start screen shake.
                if (screenShake != null)
                {
                    screenShake.Shake();
                    isScreenShaking = true;
                }

                lastShotTime = Time.time;

                if (raycastHit.collider != null)
                {
                    // Apply impulse to the hit object.
                    if (raycastHit.rigidbody != null)
                    {
                        raycastHit.rigidbody.AddForce(recoilStrength * direction, ForceMode2D.Impulse);
                    }

                    splatter.Spawn(raycastHit.point + direction * splatterOffset, direction);
                }
            }

            // Stop screen shake.
            if (screenShake != null && isScreenShaking && !Input.GetMouseButton(0))
            {
                isScreenShaking = false;
                screenShake.Stop();
            }
        }