0% found this document useful (0 votes)
5 views

Script Speed Ema Is

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Script Speed Ema Is

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// script 1

using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections;
public class SpeedScript : MonoBehaviour
{
public InputActionProperty buttonPressed;
public float speed;
private Coroutine speedCoroutine;

private void OnEnable()


{
buttonPressed.action.Enable();
buttonPressed.action.performed += OnButtonPressed;
}

private void OnDisable()


{
buttonPressed.action.Disable();
buttonPressed.action.performed -= OnButtonPressed;
}

private void OnButtonPressed(InputAction.CallbackContext context)


{
if (context.performed)
{
if (speedCoroutine != null)
{
StopCoroutine(speedCoroutine);
}
speedCoroutine = StartCoroutine(IncreaseSpeedGradually());
}
}

private IEnumerator IncreaseSpeedGradually()


{
while (speed < 7f)
{
speed += Time.deltaTime;
yield return null;
}
}
}

-----------------------------------------------------------------------------------
// script 2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotate : MonoBehaviour


{

public SpeedScript speedScript;

void Update()
{
gameObject.transform.Rotate(speedScript.speed,0,0);
}
}

You might also like