- Home /
Question by
JonathanXD12 · May 05, 2021 at 12:56 PM ·
scripting problemlisteditorwindowrotate object
rotating platforms list
I'm currently making a 2D game and I added a platform, which is rotating around a center. Now I want, that you can choose how many platforms you want to rotate around the center. like on the screenshot with the circuit points. I'm not very keen on coding, so could you just add that to my current script pls?
Thanks!
Screenshot:
Current script:
using UnityEngine;
public class Rotation_Object_System : MonoBehaviour
{
[SerializeField]
private Transform rotationCenter;
public GameObject rotationObject;
[SerializeField]
private float rotationRadius = 2f, angularSpeed = 2f;
public bool ClockwiseRotation;
public bool HideRotationCenter;
private float posX, posY, angle = 0f;
private void Start()
{
Loading_Initial_Parameters();
}
private void Update()
{
// Rotation
posX = rotationCenter.position.x + Mathf.Cos(angle) * rotationRadius;
posY = rotationCenter.position.y + Mathf.Sin(angle) * rotationRadius;
rotationObject.transform.position = new Vector2(posX, posY);
float angularMovement = Time.deltaTime * angularSpeed;
if (ClockwiseRotation)
angle -= angularMovement;
else
angle += angularMovement;
if (angle >= 360f)
angle = 0f;
}
private void Loading_Initial_Parameters()
{
if (rotationCenter.TryGetComponent<SpriteRenderer>(out var rotationCenterSpriteRenderer))
{
rotationCenterSpriteRenderer.enabled = !HideRotationCenter;
}
else
{
Debug.LogWarning(
$"Rotation Center ({rotationCenter.name}) does NOT HAVE " +
$"a SpriteRenderer Component to hide/show");
}
}
}
bildschirmfoto-2021-05-03-um-141114.png
(105.1 kB)
Comment