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
0
Question by SkullMaster259 · Jun 30, 2017 at 12:13 PM · script.

"Method must have a return type"

The error says

"Method must have a return type" Around the AddX and MinusX. Above the Add and Minus I have the code that is meant to update in realtime the position of the object. Where it gives me 2 errors on all 3 lines of code. It says "Invalid token '=' in class, struct, or interface member declaration" In the same line it says "Invalid token '(' in class,struct, or interface member declaration"

Aside from my main question if anyone knows how I can have the player select an object when he looks at it please let me know!

using System.Collections; using UnityEngine; using UnityEngine.UI;

 public class Forge_Menu : MonoBehaviour {
 
     public int x;
     public int y;
     public int z;
     public Text XCurrent;
     public Text YCurrent;
     public Text ZCurrent;
     public GameObject Selected;
 
     void Start () {
         x = PlayerPrefs.GetFloat ("ObjectX", transform.position.x);
         y = PlayerPrefs.GetFloat ("ObjectY", transform.position.y);
         z = PlayerPrefs.GetFloat ("ObjectZ", transform.position.z);
     }
 
     void Update () {
         if (PlayerPrefs.GetInt ("ObjectX") != x) {
             PlayerPrefs.SetInt ("ObjectX", x);
             PlayerPrefs.Save ();
             Debug.Log ("Save completed. X = " + x);
         }
         if (PlayerPrefs.GetInt ("ObjectY") != y) {
             PlayerPrefs.SetInt ("ObjectY", y);
             PlayerPrefs.Save ();
             Debug.Log ("Save completed. Y = " + y);
         }
         if (PlayerPrefs.GetInt ("ObjectZ") != z) {
             PlayerPrefs.SetInt ("ObjectZ", z);
             PlayerPrefs.Save ();
             Debug.Log ("Save completed. Z = " + z);
         }
         transform.Translate (x, y, z);
     }
 
     XCurrent.Text = x.ToString();
     YCurrent.Text = y.ToString();
     ZCurrent.Text = z.ToString();
 
     public AddX(){
         x++
     }
 
     public MinusX(){
         x--
     }
 
     public AddY(){
         y++
     }
 
     public MinusY(){
         x--
     }    
 
     public AddZ(){
         z++
     }
 
     public MinusZ(){
         z--
     }
 }




Comment
Add comment · Show 1
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 Saryk360 · Jun 30, 2017 at 02:30 PM 0
Share

Also if this is what I think it is, PlayerPrefs is a terrible way of saving game data. You should serialize data to a file (check this series out).

PlayerPrefs should be used only for configuration settings like language and such, as it writes directly to the registry and can become very heavy for the system. It also doesn't leave the choice of where it's saved to the user, which means their C:\ disk could get filled for no apparent reason. (on windows at least)

1 Reply

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

Answer by Saryk360 · Jun 30, 2017 at 02:25 PM

The error tells you exactly what is wrong. Your functions on lines 40 to 60 don't have a return type : since in your case they don't return a value, the return type is void.

Declare them as

      public void AddX(){
          x++
      }
  
      public void MinusX(){
          x--
      }
  
      public void AddY(){
          y++
      }
  
      public void MinusY(){
          x--
      }    
  
      public void AddZ(){
          z++
      }
  
      public void MinusZ(){
          z--
      }
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 SkullMaster259 · Jul 01, 2017 at 12:03 PM 0
Share

Thanks! That seemed to fix the problem.

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

110 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

Related Questions

error CS0120: An object reference is required to access non-static member `ScoreManager.score' 1 Answer

How to make an enemy 2d chasing player? 1 Answer

Wrong after Update? 0 Answers

warning CS0618 with unity ngui 0 Answers

Same Q as before but it has been a while and nones replyed so im reposting 2 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