Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by 10chaos1 · Oct 02, 2015 at 12:45 AM · c#errorcompile

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 10chaos1 · Oct 02, 2015 at 01:59 AM 0
Share

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'

avatar image GiyomuGames 10chaos1 · Oct 02, 2015 at 07:51 AM 0
Share

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 :)

avatar image 10chaos1 GiyomuGames · Oct 02, 2015 at 10:26 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

compile error. does not denote a valid type. 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges