Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Last active April 12, 2021 04:15
Show Gist options
  • Select an option

  • Save rsaenzi/0488df422e5517b32bdecc7871aef7d3 to your computer and use it in GitHub Desktop.

Select an option

Save rsaenzi/0488df422e5517b32bdecc7871aef7d3 to your computer and use it in GitHub Desktop.
Script for Unity to rotate a GameObject around Y axis with constant rotation speed
//
// SelfRotation.cs
//
// Created by Rigoberto Sáenz Imbacuán (https://linkedin.com/in/rsaenzi/)
// Copyright © 2021. All rights reserved.
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfRotation : MonoBehaviour {
[Tooltip("Rotation speed around its Y axis in degrees/seconds")]
public float rotationSpeed;
void Update() {
// Rotates the game object ´rotationSpeed´ degrees per second
this.transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime, Space.Self);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment