Skip to content

Instantly share code, notes, and snippets.

@divide-by-zero
Last active November 19, 2020 05:41
Show Gist options
  • Save divide-by-zero/6739c4f8271f9e1ae082975447ebad9c to your computer and use it in GitHub Desktop.
Save divide-by-zero/6739c4f8271f9e1ae082975447ebad9c to your computer and use it in GitHub Desktop.
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