Hi, I have this script in US, I have been trying to translate it to C# but I don’t know how to use quaternions, eulers and that stuff I hope you can help me here is the code in JS and below the code in C#, thanks in advance.
#pragma strict
var qTo : Quaternion;
var speed = 1.25;
var rotateSpeed = 3.0;
var timer = 0.0;
function Start()
{
qTo = Quaternion.Euler(Vector3(0.0,0.0, Random.Range(-30, 30)));
}
function Update() {
timer += Time.deltaTime;
if(timer > 2)
{
qTo = Quaternion.Euler(Vector3(0.0,0.0,Random.Range(-30, 30)));
timer = 0.0;
}
transform.rotation = Quaternion.Slerp(transform.rotation, qTo, Time.deltaTime * rotateSpeed);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
and the code in C#, I only got one error in the line 24 where transform.position is:
using UnityEngine;
using System.Collections;
public class POLICEscript : MonoBehaviour {
private Quaternion qTo;
float speed = 1.5f;
float rotateSpeed = 3.0f;
public float timer = 0.0f;
void Start()
{
qTo = Quaternion.Euler (new Vector3 (0.0f, 0.0f, Random.Range (-30f, 30f)));
}
void Update()
{
timer += Time.deltaTime;
if(timer > 2)
{
qTo = Quaternion.Euler (new Vector3 (0.0f, 0.0f, Random.Range (-30f, 30f)));
timer = 0.0f;
//transform.position = Quaternion.Slerp(transform.rotation, qTo, Time.deltaTime * rotateSpeed);
transform.position = Quaternion.Slerp(transform.rotation, qTo, Time.deltaTime * rotateSpeed);
transform.Translate (Vector3.forward * speed * Time.deltaTime);
}
}
}