- Home /
Hand spinner script
Hello guys, today i am trying to make hand spinner game (screenshot) So i am using this script as a test to test the rotation : my question here is how i can get the speed from user without adding it as a variable inside the script. is there a function to call ? please help i am stuck
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spin : MonoBehaviour {
public float speed = 10f;
public float Zaxis = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey("up"))
RotateLeft();
}
void RotateLeft () {
transform.Rotate (0, 0, Zaxis * Time.deltaTime);
}
}
I don't really understand your question. Where do you want to get the speed from? From the script you posted?
from user's phone android per example this game https://play.google.com/store/apps/details?id=com.smashlab.fidgetspinnersimulator
$$anonymous$$ay I ask why you don't want to store it into a variable?
here is the example of what i want in result https://play.google.com/store/apps/details?id=com.smashlab.fidgetspinnersimulator
Answer by jmgek · May 23, 2017 at 08:07 PM
You don't want to use 'if (Input.GetKey("up"))' because there is no key associated with mobile. You're looking for 'input.GetTouch' then calculate how fast the fingers are moving and apply it to your RotateLeft:
https://docs.unity3d.com/ScriptReference/Input.GetTouch.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public float speed = 0.1F;
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
// Get movement of the finger since last frame
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
}
Your answer
Follow this Question
Related Questions
How do I rotate arround an object by swiping left or right? 0 Answers
2D wheel spin 2 Answers
Problem with Quaternion.LookRotation() 1 Answer
Rotation problem 1 Answer