Last active
November 19, 2020 05:41
-
-
Save divide-by-zero/6739c4f8271f9e1ae082975447ebad9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerBall : MonoBehaviour | |
{ | |
[SerializeField] | |
private float rotSpeed = 100; | |
[SerializeField] | |
private float moveSpeed; | |
private Vector2? oldMousePos; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
transform.Rotate(Time.deltaTime * rotSpeed,0,0); | |
var speed = 0.0f; | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
oldMousePos = Input.mousePosition; | |
} | |
if (Input.GetMouseButton(0) && oldMousePos.HasValue) | |
{ | |
speed = oldMousePos.Value.x - Input.mousePosition.x; | |
oldMousePos = Input.mousePosition; | |
} | |
else | |
{ | |
oldMousePos = null; | |
} | |
transform.position += new Vector3(Time.deltaTime * speed * moveSpeed,0,0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment