Mathf.Clamp Negative Rotation for the 10th Million Time

Hello Guys,
i know this questions gets asked a lot but i got this small c# script working so far but there is a stuttering when i want to clamp it in the negative rotation. I usually work with playmaker but want to force me scripting things that cant be done correctly or like this with so few lines of code :wink:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gun_Lockrotation : MonoBehaviour {

	public float MaxDepression = -5f;
	public float MaxElevation = 20f;

	void LateUpdate()
	{
		transform.localEulerAngles = new Vector3 (Mathf.Clamp(transform.localEulerAngles.x, MaxDepression, MaxElevation), transform.localEulerAngles.y, transform.localEulerAngles.z);
	}
}

Greetings,
Jasper

For everyone who is interested, i got this code working with the information from another Question; link text

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gun_Lockrotation : MonoBehaviour 
{

	public float MaxDepression = -20f;
	public float MaxElevation = 8f;


	void Update()
	{
		transform.localEulerAngles = new Vector3 (Mathf.Clamp((transform.localEulerAngles.x <= 180) ? transform.localEulerAngles.x : -(360 - transform.localEulerAngles.x), MaxDepression, MaxElevation), transform.localEulerAngles.y, transform.localEulerAngles.z);
	}
}

This is my sample for clamping negative Rotations for something like a Tank Barrel or something :slight_smile:

Thanks so much that works as a charm !