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)

2 Answers

2

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

ahhh that makes more sense. Good job.

no tnk you 4 taking time to help me :)

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 camMouse, as in your script, there is no property, it's just var camMouse, while in C# I need something like GameObject camMouse

You can declare it as a GameObject, Like this GameObject camMouse = GameObject.Find("Main Camera"); to access it you can do something like this camMouse.GetComponent<MouseLook>();