- Home /
compile error with this script
after implementing the fix recomendedby Guidanel i now have this error error CS0019: Operator +=' cannot be applied to operands of type
UnityEngine.Quaternion' and `int' at lines 55 and 61 of this script
using UnityEngine;
using System.Collections;
public class movecamera : MonoBehaviour {
public int edgeboundry = 10;
public int minheight;
public int maxheight;
bool minheightreached;
bool maxheightreached;
public int rotspeed;
void Awake ()
{
minheightreached = false;
maxheightreached = false;
}
void Update ()
{
minheightreached = transform.position.y <= minheight;
maxheightreached = transform.position.y >= maxheight;
if (Input.GetAxis ("Vertical") < 0 * Time.deltaTime){
transform.position += new Vector3 (0, 0, -0.2f);
}
if (Input.GetAxis ("Vertical") > 0 * Time.deltaTime){
transform.position += new Vector3 (0, 0, 0.2f);
}
if (Input.GetAxis ("Horizontal") < 0 * Time.deltaTime){
transform.position += new Vector3 (-0.2f, 0, 0);
}
if (Input.GetAxis ("Horizontal") > 0 * Time.deltaTime){
transform.position += new Vector3 (0.2f, 0, 0);
}
if (Input.GetKey("q") || (Input.GetMouseButtonDown(2))){
transform.rotation += rotspeed;
}
if (Input.GetKey("e") || (Input.GetMouseButtonDown(2))){
transform.rotation += -rotspeed;
}
if(Input.GetAxis("Ymovement") > 0.0f && (maxheightreached == false))
{
transform.position += new Vector3(0, 0.2f, 0);
}
if(Input.GetAxis("Ymovement") < 0.0f && (minheightreached == false))
{
transform.position += new Vector3(0, -0.2f, 0);
}
}
}
could someone advise me on what im doing wrong thanks in advance
Answer by GiyomuGames · Oct 02, 2015 at 01:28 AM
You put too many parenthesis.
if (Input.GetKey("q")) || (Input.GetMouseButtonDown("2"))
should be
if (Input.GetKey("q") || Input.GetMouseButtonDown("2"))
same for the following if statement.
thank you that fixed it but i have a small problem ill include the new code as the section under the previous bit is giving me this
error CS0019: Operator +=' cannot be applied to operands of type
UnityEngine.Quaternion' and `int'
Hello there.
Yeah you can't add int to Quaternion. You should have a look at http://docs.unity3d.com/ScriptReference/Quaternion.html
Let's say you want the object to rotate around the Y axis, what you may want to do is: transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + rotspeed, transform.rotation.eulerAngles.z);
Also just a bit of advice but you seem quite new to program$$anonymous$$g. So maybe it would be good to check some course or tutorial about C# at the same time :)
ok after taking you advice into amount i looked online and added this to the code in place of my previous rotation code
if (Input.GetAxis ("$$anonymous$$ouse ScrollWheel") > 0) {
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
if (Input.GetAxis ("$$anonymous$$ouse ScrollWheel") < 0) {
transform.Translate(Vector3.back * speed * Time.deltaTime);
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Q)){
transform.RotateAround(Vector3.up,0.2f * speed * Time.deltaTime);
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E)){
transform.RotateAround(Vector3.up,-0.2f * speed * Time.deltaTime);
}
and now it works as intended thank you for your help
Your answer
Follow this Question
Related Questions
NotSupportedException: Microsoft.CSharp.CSharpCodeProvider::.ctor error 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
error compiling c# 1 Answer