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 /
  • Help Room /
avatar image
1
Question by modulo34 · Sep 14, 2015 at 10:19 AM · collidertagteleport

error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Hi! I pretty new to c# , i trying to make a script to "teleport" the player to another "scene" when it enter a collider,also with a little gui asking him if he want to enter the scene, just press "f",finally removing the little gui when it exit the trigger,but i got this error

TeleporterC.cs(46,41):error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Line 46 is the last function OnTriggerExit,with the drawGui variable..

 using UnityEngine;
 using System.Collections;
 
 public class TeleporterC : MonoBehaviour {
     
     public string teleportToMap = "Level1";
     public string spawnPointName = "PlayerSpawn1"; //Use for Move Player to the SpawnPoint Position
     public string toText = ""; //What you want the target location to say on-screen
 
     private bool drawGui = false; //Control for the GUI group layout
 
     void Update(){
 
         if(drawGui == true && Input.GetKeyDown(KeyCode.F)){
             ChangeMap();
         }
     }
 
     void OnTriggerEnter(Collider other){
 
         if(other.tag == "Player"){
             other.GetComponent<StatusC>().spawnPointName = spawnPointName;
             ChangeMap();
         }        
     }
 
     void ChangeMap(){
 
         Application.LoadLevel (teleportToMap);
     }
 
     void OnGui(){
 
         if(drawGui == true){
             GUI.skin.box.fontSize = 18;
             GUI.backgroundColor = Color(255,0,0,0);
             GUI.BeginGroup(Rect(Screen.width /2 - 75,Screen.height /2 - 0,200,75));
             GUI.Box(Rect(0,0,200,25),"Press F to Enter");
             GUI.Box(Rect(0,22,200,25),toText);
             GUI.EndGroup();
         }
     }
 
     void OnTriggerExit(Collider other){
         if(other.tag == "Player"){
             drawGui == false;
         }
     }      
 }

What cause me this error,anyone?

Thank you

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

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by bubzy · Sep 14, 2015 at 01:57 PM

you can't

 drawGui == false;

you must

 drawGui = false;


:)

always check for silly errors.

Comment
Add comment · Show 1 · 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 modulo34 · Sep 14, 2015 at 06:06 PM 0
Share

Oh...:)

Thank!

avatar image
3

Answer by cliffordyohannan · Mar 18, 2017 at 06:26 PM

In my case I am Instantiating gameobject,but not assigned to a gameobject means

 Instantiate(...);

When I changed code to

 GameObject object = Instantiate(...);

error goes away.May help some one with same problem.

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Teleport using keypress (C#) 0 Answers

Making Portals 2 Answers

How to make OnTriggerEnter Only work for certain Gameobjects? 2 Answers

Check if a object with a specific tag exists in an array 1 Answer

Check where my object will be able to fit on teleport 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