示例#1
0
        protected virtual void Update()
        {
            var localPosition = transform.localPosition;
            var targetX       = (Input.mousePosition.x - Screen.width / 2) * MoveScale;
            var targetY       = (Input.mousePosition.y - Screen.height / 2) * MoveScale;

            localPosition.x = D2dHelper.Dampen(localPosition.x, targetX, MoveSpeed, Time.deltaTime);
            localPosition.y = D2dHelper.Dampen(localPosition.y, targetY, MoveSpeed, Time.deltaTime);

            transform.localPosition = localPosition;

            // Left click?
            if (Input.GetMouseButtonDown(0) == true)
            {
                var mainCamera = Camera.main;

                if (MuzzlePrefab != null)
                {
                    Instantiate(MuzzlePrefab, transform.position, Quaternion.identity);
                }

                if (BulletPrefab != null && mainCamera != null)
                {
                    var position = mainCamera.ScreenToWorldPoint(Input.mousePosition);

                    Instantiate(BulletPrefab, position, Quaternion.identity);
                }
            }
        }
示例#2
0
        protected virtual void FixedUpdate()
        {
            if (AttachedRigidbody == null)
            {
                AttachedRigidbody = GetComponentInChildren <Rigidbody2D>();
            }

            if (AttachedRigidbody != null)
            {
                if (oldPositionSet == false)
                {
                    oldPositionSet = true;
                    oldPosition    = transform.position;
                }

                var newPosition   = (Vector2)transform.position;
                var deltaPosition = newPosition - oldPosition;
                var deltaSpeed    = deltaPosition.magnitude / Time.fixedDeltaTime;
                var expectedSpeed = deltaSpeed * Vector2.Dot(transform.up, AttachedRigidbody.transform.up);

                oldPosition = newPosition;

                // Match ground speed
                Speed = D2dHelper.Dampen(Speed, expectedSpeed, GripDampening, Time.fixedDeltaTime);

                // Apply speed difference
                var deltaWheel = (Vector2)transform.up * Speed * Time.fixedDeltaTime;

                AttachedRigidbody.AddForceAtPosition(deltaWheel - deltaPosition, transform.position, ForceMode2D.Impulse);

                // Slow wheel down
                Speed = D2dHelper.Dampen(Speed, 0.0f, Friction, Time.fixedDeltaTime);
            }
        }
        protected virtual void Update()
        {
            var targetAngle = Input.GetAxisRaw("Horizontal") * SteerAngleMax;

            currentAngle = D2dHelper.Dampen(currentAngle, targetAngle, SteerAngleDampening, Time.deltaTime);

            for (var i = 0; i < SteerWheels.Length; i++)
            {
                SteerWheels[i].transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -currentAngle);
            }
        }
        protected virtual void LateUpdate()
        {
            Shake = D2dHelper.Dampen(Shake, 0.0f, ShakeDampening, Time.deltaTime);

            var shakeStrength = Shake * ShakeScale;
            var shakeTime     = Time.time * ShakeSpeed;
            var offset        = Vector2.zero;

            offset.x = Mathf.PerlinNoise(offsetX, shakeTime) * shakeStrength;
            offset.y = Mathf.PerlinNoise(offsetY, shakeTime) * shakeStrength;

            transform.localPosition = offset;
        }
        protected virtual void Update()
        {
            // Update flipping if the game is playing
            if (Application.isPlaying == true)
            {
                cooldown -= Time.deltaTime;

                // Flip?
                if (cooldown <= 0.0f)
                {
                    FrontShowing = !FrontShowing;

                    ResetCooldown();
                }
            }

            // Get target angle based on flip state
            var targetAngle = FrontShowing == true ? 0.0f : 180.0f;

            // Slowly rotate to the target angle if the game is playing
            if (Application.isPlaying == true)
            {
                angle = D2dHelper.Dampen(angle, targetAngle, FlipSpeed, Time.deltaTime);
            }
            // Instantly rotate if it's not
            else
            {
                angle = targetAngle;
            }

            transform.localRotation = Quaternion.Euler(0.0f, angle, 0.0f);

            // Make the destructible indestructible if it's past 90 degrees
            if (Destructible != null)
            {
                Destructible.Indestructible = targetAngle >= 90.0f;
            }

            // Update movement
            MoveProgress += MoveSpeed * Time.deltaTime;

            var moveDistance = (EndPosition - StartPosition).magnitude;

            if (moveDistance > 0.0f)
            {
                var progress01 = Mathf.PingPong(MoveProgress / moveDistance, 1.0f);

                transform.localPosition = Vector3.Lerp(StartPosition, EndPosition, Mathf.SmoothStep(0.0f, 1.0f, progress01));
            }
        }
        protected virtual void Update()
        {
            currentThrottle = D2dHelper.Dampen(currentThrottle, Throttle, Dampening, Time.deltaTime);

            transform.localScale = MaxScale * Random.Range(1.0f - Flicker, 1.0f + Flicker) * currentThrottle;
        }