Hello to all guys
I am new here because I am new to the world of unity.
I write to u because some weeks ago I beginned studing scripts and how they works.
I am reading the Unity 3.x Game Developement essential and following the exercises and tutorials.
During one of these, I decided to create a turret that rotate on X axis with a limit on its range of rotation (please see the attached image to have a best idea of what I am writing about).
So in order to make my project real in the monodevelop first I create the script to rotate the cannon using uparrow and down arrow, here u are what I did in C#:
public class cannon : MonoBehaviour {
public float m_RotationSpeed = 15;
void Start () {
}
void Update ()
{
float xcontrol = m_RotationSpeed * Time.deltaTime;
float xrot = transform.rotation.eulerAngles.x;
if(Input.GetKey(KeyCode.UpArrow)
{
transform.Rotate(xcontrol,0,0);
}
if(Input.GetKey(KeyCode.DownArrow))
{
transform.Rotate(-xcontrol,0,0);
}
}
}
Then I create a variable xrot in order to register the angle of the x axis hoping to use it to limit the range of the rotation with an “if” function, but this way seems to be really wrong after hunderd of attempts.
So, I am now at a blind point (a poor point in effect) because I don’tknow what I need to do in order to realize mi porject.
Searching on the web I found a lot of scripts that use a misterous (misterius for me) function called Mathf.Clamp.
I am a true beginner in scripting but I really want to understand and imporve so I am here to ask for your help.
Could anyone help me please?
I need someone that would like to write the script for me and explain the functions and how they works. Please I am a true beginner so use the most simple way to explian because it’s easy for me get confused, sorry aboutthat. I prefer C# examples, I have never work using Java.
I know it’s a boring issue but for me it’s very important.
Thank you for the attention and hope to hear form you soon!
Best regards
Matthew