Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 ART_AGE · Aug 07, 2015 at 04:10 PM · camerarotationsavemouselookfirst-person-controller

Save Camera Rotation ERROR (HELP!!!!)

I need to save my camera rotation (from MouseLook.cs) I use this script :

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO; 
 
 namespace UnityStandardAssets.Characters.FirstPerson
 {
     
     public class QuickSave : MonoBehaviour 
     { 
         public string fileName = "QuickSave";
         
         [System.Serializable]
         class PR
         {        
             public float MRX;
             public float MRY;
             
         }
         
         public void Save(){
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = new FileStream(Application.persistentDataPath +"/"+ "SaveFile", FileMode.Create);
             PR newData = new PR();
             newData.MRX=GetComponent<MouseLook>().xRot ;
             newData.MRY=GetComponent<MouseLook>().yRot ;
             bf.Serialize(file, newData);
             file.Close();
         }
         
         public void Load(){
             if (File.Exists(fileName)){
                 BinaryFormatter bf = new BinaryFormatter();
                 FileStream file = new FileStream(Application.persistentDataPath +"/"+ "SaveFile", FileMode.Open,FileAccess.Read);
                 PR newData1 = (PR)bf.Deserialize(file);
                 GetComponent<MouseLook>().xRot = newData1.MRX;
                 GetComponent<MouseLook>().yRot = newData1.MRY;
                 file.Close();
             }
         }
         
         void LateUpdate () {
             if (Input.GetKey (KeyCode.F5)) 
             {   
                 Save();   
             } 
             if (Input.GetKey (KeyCode.F9)) 
             {   
                 Load();   
             }
         }
     }
 }

When I Save rotation I get ERROR: ArgumentException: GetComponent requires that the requested component 'MouseLook' derives from MonoBehaviour or Component or is an interface.

When I Load rotation I get ERROR: SerializationException: serializationStream supports seeking, but its length is 0

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

Answer by allenallenallen · Aug 07, 2015 at 04:19 PM

You need to declare the game object of where the MouseLook script is attached to.

Perhaps something like this:

 public GameObject player; // Drag the game object that has MouseLook attached to it.

And add "player" right before all of your GetComponent.

For example:

 newData.MRX = player.GetComponent<MouseLook>().xRot ;
 
 player.GetComponent<MouseLook>().xRot = newData1.MRX;

Comment
Add comment · Show 6 · 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 ART_AGE · Aug 07, 2015 at 05:33 PM 0
Share

It's not work

ArgumentException: GetComponent requires that the requested component '$$anonymous$$ouseLook' derives from $$anonymous$$onoBehaviour or Component or is an interface.

avatar image allenallenallen · Aug 08, 2015 at 02:59 AM 1
Share

Well, where is $$anonymous$$ouseLook? Is it a component of an instance?

avatar image ART_AGE · Aug 08, 2015 at 10:20 AM 0
Share

$$anonymous$$ouseLook - Standart assets script (Package : Character) Script ($$anonymous$$ouseLook) at the same place where my script (Save)

avatar image allenallenallen · Aug 08, 2015 at 10:22 AM 0
Share

That's not what I'm asking though. You have to attach this script to a game object, right? Or else it won't run. It'll just sit there.

avatar image ART_AGE · Aug 08, 2015 at 11:26 AM 0
Share

This script I attached to game object (Prefab) but it is not work

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make camera rotation relative to target. 3 Answers

How do I disable mouse to turning right 0 Answers

Mathf.Clamp is 'Sticky'? 1 Answer

First Person Camera Rotation 360 degrees on all axis 0 Answers

Camera X and Y velocity HELP! 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