Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 mr98757660 · Apr 17, 2021 at 10:34 AM · scripting problembutton trigger eventssaveloadcontextmenu

Question about different on running method in [ContextMenu("xxx")] and onClick() in UI Button

Hi guys, i've experienced some weired issue for my SAVELOAD. When i use [ContextMenu("xxx")] to run my method i can immediatetly go to the position i stored. But when i use onClick() in UI Button to call my method i cant move my player's position (I'm using this video to create my saveLoad https://www.youtube.com/watch?v=f5GvfZfy3yk&t=708s)

this is how i restore my data`using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI;

namespace Assets.GameSystem.SaveSystem3 { public class LevelSystem : MonoBehaviour, ISaveable { public GameObject player; public GameObject text1; public GameObject timerText; public TimerController timerController; public TriggerArea triggerArea1; public TriggerArea triggerArea2; public TriggerArea triggerArea3; [SerializeField] private string level = "Menu"; [SerializeField] public float pX; [SerializeField] public float pY; [SerializeField] public float pZ; [SerializeField] public float rX; [SerializeField] public float rY; [SerializeField] public float rZ; [SerializeField] private string achievment; [SerializeField] private bool achieve11 = false; [SerializeField] private bool achieve22 = false; [SerializeField] private bool achieve33 = false; [SerializeField] private string timer; [SerializeField] private float s; [SerializeField] private int m; [SerializeField] private int h;

     public object CaptureState()
     {
         return new SaveData
         {
             level = level,
             pX = player.transform.position.x,
             pY = player.transform.position.y,
             pZ = player.transform.position.z,
             rX = player.transform.rotation.x,
             rY = player.transform.rotation.y,
             rZ = player.transform.rotation.z,
             achievment = text1.GetComponent<Text>().text,
             achieve11 = triggerArea1.achive1,
             achieve22 = triggerArea2.achive2,
             achieve33 = triggerArea3.achive3,
             s = timerController.secondsCount,
             m = timerController.minuteCount,
             h = timerController.hourCount
         };
     }

     public void RestoreState(object state)
     {
         var saveData = (SaveData)state;

         level = saveData.level;
         pX = saveData.pX;
         pY = saveData.pY;
         pZ = saveData.pZ;
         rX = saveData.rX;
         rY = saveData.rY;
         rZ = saveData.rZ;

         player.transform.position = new Vector3(pX, pY, pZ);
         player.transform.eulerAngles = new Vector3(rX, rY, rZ);

         //player.transform.position = playerPosition;
         //player.transform.eulerAngles = playerRotation;

         achievment = saveData.achievment;
         text1.GetComponent<Text>().text = achievment;

         achieve11 = saveData.achieve11;
         triggerArea1.achive1 = achieve11;
         achieve22 = saveData.achieve22;
         triggerArea2.achive2 = achieve22;
         achieve33 = saveData.achieve33;
         triggerArea3.achive3 = achieve33;

         s = saveData.s;
         timerController.secondsCount = s;
         m = saveData.m;
         timerController.minuteCount = m;
         h = saveData.h;
         timerController.hourCount = h;

     }

     [Serializable]
     private struct SaveData
     {
         public string level;
         public float pX;
         public float pY;
         public float pZ;
         public float rX;
         public float rY;
         public float rZ;
         public string achievment;
         public bool achieve11;
         public bool achieve22;
         public bool achieve33;
         public string timer;
         public float s;
         public int m;
         public int h;
         //public Text text;
     }
 }

}` alt text

unknow231n.png (51.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

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

My UI Buttons stopped working 0 Answers

How to create simple stage systems? 1 Answer

[C#] Save/Load Score stays at 0 even when changed 2 Answers

How to save field changes to scene file using ContextMenu? 1 Answer

OnClick() animation 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