Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@WakkyFree
Last active February 27, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WakkyFree/3de4f2f8bb596a111699d357bfb42c67 to your computer and use it in GitHub Desktop.
Save WakkyFree/3de4f2f8bb596a111699d357bfb42c67 to your computer and use it in GitHub Desktop.
Script for Unity
using UnityEngine;
using System.Collections;
public class SwingBat : MonoBehaviour {
private int r = 12; // Rotation Speed
private int r_sum = 0;
private int r_max = 360;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0) && r_sum < r_max) { // Pressed left click
transform.Rotate(0, -r, 0);
r_sum += r;
} else if (!Input.GetMouseButton(0) && r_sum != 0) {
transform.Rotate(0, r, 0);
r_sum -= r;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment