- Home /
 
how can I disable all camera movements trough GUI?
I made a play button and when clicked it has the option of 2 GUI ...1 to load game ....2 to start a new game... my question is how can I stop all camera movement when the play button is pressed....ohh and the script is attached to the 3d text and not the camera.
the script...(java)..
 // ***********************************************************************
 import System;
 import System.Xml;
 import System.Xml.Serialization;
 import System.IO;
 import System.Text;
 
 var shownewgame : boolean = false;
 var showback : boolean = false;
 var showcontinue : boolean = false;
 var levelToLoad : String;
 var soundhover : AudioClip;
 var beep : AudioClip;
 var QuitButton : boolean = false;
 //*************************************************************************
 private var _Save : Rect;
 private var _Load : Rect;
 
 private var _SaveMSG : Rect;
 private var _LoadMSG : Rect;
 
 //var _ShouldSave : boolean;
 //var _ShouldLoad : boolean;
 //var _SwitchSave : boolean;
 //var _SwitchLoad : boolean;
 private var _FileLocation : String;
 private var _FileName : String = "SaveData.xml";
 
 //public GameObject player;
 var player : GameObject;
 var playerName : String = "Default";
 
 var MyStyle : GUIStyle;
 
 private var myData : UserData;
 private var _data : String;
 
 private var VPosition : Vector3;
 //*******************************************************************************
 
 function Awake () { 
       // XML Save/Load path
       _FileLocation=Application.dataPath;
       
           
       // Creating something to store information into.
      myData=new UserData();
     }
 //*********************************************************************************
 
 function OnMouseEnter(){
 audio.PlayOneShot(soundhover);
 }
 function OnMouseUp(){
 animation.CrossFade("PlayButtonAnimation");
 audio.PlayOneShot(beep);
 yield new WaitForSeconds(0.1);
 if(QuitButton){
 Application.Quit();
 }
 shownewgame = true;
 showcontinue = true;
 showback = true;
 
 }  
 
 function Update(){}
 
 function OnGUI(){
 if(shownewgame == true){
     if(GUI.Button(Rect(0,40,200,30),"New Game")){
        Application.LoadLevel(levelToLoad); //Code for new game button
     }
 }
 if(showcontinue == true){
                   
                    //code for continue button
      if(GUI.Button(Rect(0,80,200,30),"Continue")){
     
     GUI.Label(_LoadMSG,"Loading from: "+_FileLocation);
       // Load our UserData into myData
       LoadXML();
       if(_data.ToString() != "")
       {
          myData = DeserializeObject(_data);
          VPosition=new Vector3(myData._iUser.x,myData._iUser.y,myData._iUser.z);             
          player.transform.position=VPosition;
          curExperience = myData._iUser.experience;
          Debug.Log("Load Successful");
       }
     }
 }
 if(showback == true){
 if(GUI.Button(Rect(0,120,200,30),"Back")){
      showcontinue =false;
      shownewgame =false;
      showback =false;
 }
 }
 }
 //**********************************************************************************************
 
 //XML Code ************************************************************************************
 
 function UTF8ByteArrayToString(characters : byte[] )
 {     
    var encoding : UTF8Encoding  = new UTF8Encoding();
    var constructedString : String  = encoding.GetString(characters);
    return (constructedString);
 }
 
 
 function StringToUTF8ByteArray(pXmlString : String)
 {
    var encoding : UTF8Encoding  = new UTF8Encoding();
    var byteArray : byte[]  = encoding.GetBytes(pXmlString);
    return byteArray;
 }
    
 
 function SerializeObject(pObject : Object)
 {
    var XmlizedString : String  = null;
    var memoryStream : MemoryStream  = new MemoryStream();
    var xs : XmlSerializer = new XmlSerializer(typeof(UserData));
    var xmlTextWriter : XmlTextWriter  = new XmlTextWriter(memoryStream, Encoding.UTF8);
    xs.Serialize(xmlTextWriter, pObject);
    memoryStream = xmlTextWriter.BaseStream; // (MemoryStream)
    XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
    return XmlizedString;
 }
 
 
 function DeserializeObject(pXmlizedString : String)   
 {
    var xs : XmlSerializer  = new XmlSerializer(typeof(UserData));
    var memoryStream : MemoryStream  = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
    var xmlTextWriter : XmlTextWriter  = new XmlTextWriter(memoryStream, Encoding.UTF8);
    return xs.Deserialize(memoryStream);
 }
 
 
 function CreateXML()
 {
    var writer : StreamWriter;
 
    var t : FileInfo = new FileInfo(_FileLocation+"/"+ _FileName);
    if(!t.Exists)
    {
       writer = t.CreateText();
    }
    else
    {
       t.Delete();
       writer = t.CreateText();
    }
    writer.Write(_data);
    writer.Close();
    Debug.Log("File written");
 }
    
 function LoadXML()
 {
    //StreamReader r = File.OpenText(_FileLocation+"\\"+ _FileName);
    var r : StreamReader = File.OpenText(_FileLocation+"/"+ _FileName);
    var _info : String = r.ReadToEnd();
    r.Close();
    _data=_info;
    Debug.Log("File Read");
 }
 
 //EndOfXML Code **************************************************************
 
 
 @script RequireComponent(AudioSource)
 
              Answer by darkcookie · Apr 10, 2012 at 08:08 AM
i found the answer ......
 private var camMouse;
 
 function Start () {
 
 camMouse = gameObject.Find("Main Camera").GetComponent("MouseLook");
 
 } 
 function Update(){
 if (shownewgame == true){
 Screen.showCursor = !Screen.showCursor;
 Screen.showCursor = true;
 camMouse.enabled = !camMouse.enabled;
 }
 }
 
              Can anyone make this script in C#? Or at least tell me how I should declare cam$$anonymous$$ouse, as in your script, there is no property, it's just var cam$$anonymous$$ouse, while in C# I need something like GameObject cam$$anonymous$$ouse
You can declare it as a GameObject, Like this
  GameObject cam$$anonymous$$ouse = GameObject.Find("$$anonymous$$ain Camera");
 
                  to access it you can do something like this
 cam$$anonymous$$ouse.GetComponent<$$anonymous$$ouseLook>();
 
                 Answer by Lttldude · Apr 10, 2012 at 07:56 AM
I'm not sure of the context of you script, but when the play button is pressed, you can grab the current position of the camera and store it in a variable. Then you can change a new variable called stopCamera to true. Then in the update function, a conditional statement will fix the camera's position to that Vector3. When you want it to stop fixing the camera's position, then make stopCamera false.
kind of like this:
 var fixedCameraPos : Vector3;
 var stopCamera : boolean = false;
 
 function Update() {
 if(stopCamera) {
 Camera.main.transform.position = fixedCameraPos;
 }
 }
 
               Ideally you could stop the source of the camera's movement directly. How is the camera moving (following script, iTween, etc)?
thank you for the responce ...and i found the answer already thank you tho ...and its not moving ...only rotating ....its a 3d menu ..
Your answer
 
             Follow this Question
Related Questions
How to handle FPSCharacter movement using Google daydream controller touchpad? 0 Answers
GUI box not moving with game object on X axis 0 Answers
how can i disable camera movement 1 Answer
Hide GUI while switchcam 3 Answers
Keeping an object constrained to a 2d radius based off of the camera 0 Answers