• 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 /
  • Help Room /
This question was closed Apr 14, 2019 at 12:56 PM by $$anonymous$$ for the following reason:

Other

avatar image
Question by $$anonymous$$ · Apr 20, 2016 at 03:50 PM · c#unity5unexpected-symbol

C# - Unexpected Symbol ERROR?

So I have written this code, and I have been searching a lot of unity 3d questions, but I can't find the one I need. So basically on line 34 and 38 there seems to be an error with the "=" symbol. I am really confused on this one. (The code disables MouseLook when you press ESC and enables it with a button that says Resume Game)

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class UIManager : MonoBehaviour {
 
     public GameObject PausePanel;
 
     public bool isPaused;
 
     // Use this for initialization
     void Start () {
         isPaused = false;
     }
 
     // Update is called once per frame
     void Update () {
         if (isPaused) {
             PauseGame (true);
         } 
         else {
             PauseGame (false);
         }
 
         if (Input.GetButtonDown ("Cancel")) {
             SwitchPause (); 
         }
     }
 
     void PauseGame (bool state){
         if (state) {
             PausePanel.SetActive (true);
             Time.timeScale = 0.0f; //Paused
             MouseLook MouseLook = GameObject.Find( "Player" ).GetComponent( "MouseLook" ) as MouseLook.MouseLook.enabled = false;
         } else {
             Time.timeScale = 1.0f; //Unpaused
             PausePanel.SetActive (false);
             MouseLook MouseLook = GameObject.Find( "Player" ).GetComponent( "MouseLook" ) as MouseLook.MouseLook.enabled = true;
         }
     }
 
     public void SwitchPause () { 
         if (isPaused){
             isPaused = false;
         }
         else {
             isPaused = true;
         }
     }
 }
Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by TBruce · Apr 20, 2016 at 04:23 PM

@TacomanLuke

Without knowing what the class MouseLook looks like I can at least say that there seems to be several issues with both these statements.

  1. "MouseLook MouseLook = " is invalid, the defined variable cannot be the same as the data type. Try MouseLook mouseLook = instead.

  2. MouseLook.MouseLook is invalid

  3. "MouseLook.MouseLook.enabled = true;" is invalid because you cannot implicitly convert type `bool'

Try the following instead

 if ((GameObject.Find( "Player") != null) && (GameObject.Find( "Player").GetComponent( "MouseLook") != null))
 {
     GameObject.Find( "Player" ).GetComponent( "MouseLook" ).enabled = true;
 }
 

or better yet if you have tagged you player as "Player" do this

 if ((GameObject.FindWithTag( "Player") != null) && (GameObject.FindWithTag( "Player").GetComponent( "MouseLook") != null))
 {
     GameObject.FindWithTag( "Player" ).GetComponent( "MouseLook" ).enabled = true;
 }
Comment

People who like this

0 Show 0 · 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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

147 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 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 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 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 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

Find the closest of two named gameobjects? 0 Answers

how can i get a checkpoint move in unity cardboard vr 0 Answers

How do I create a Continuous Turn in XR for my VR Rig instead of Snap Turn Provider? 0 Answers

,Unity Custom Inspector CreateInspectorGUI redraw on change 1 Answer

Return transform to normal rotation after rotation key pressed? 0 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