- Home /
HELP ME PLEASE!----------------------------!?
// Script that puts a window on-screen where the player can toggle who he controls // It works by sending SetControllable messages to turn the different characters on and off. // It also changes who the CameraScrolling scripts looks at.
// An internal reference to the attached CameraScrolling script private var cameraScrolling : CameraScrolling; // Who is the player controlling private var selected = 0;
var PatriotTagName: String = "Patriot"; // List of objects to control //var targets : Transform[]=FindObjectsOfType(Transform) as Transform[]; var targets : Transform[];// = new Transform[1]; //var convertedTargets : Array = new Array(targets); // What to display on the buttons in the window var targetButtonNames : String[]; //var target:Rigidbody; ///////////////////////////////////////////////////////////////////////////////////////// //var target:Transform;
// On start up, we send the SetControllable () message to turn the different players on and off. function Awake () { //targets = GameObject.FindWithTag("Patriot").transform; ///////////////////////////////////////////////////////////////////////////////////////////// // Get the reference to our CameraScrolling script attached to this camera; cameraScrolling = GetComponent (CameraScrolling);
// Set the scrolling camera's target to be our character at the start.
cameraScrolling.SetTarget (targets[0], true);
// tell all targets (except the first one) to switch off.
for (var i=0; i < convertedTargets.length; i++)
targets[i].gameObject.SendMessage ("SetControllable", (i == 0), SendMessageOptions.DontRequireReceiver);
}
function Update(){ //targets = transform.FindGameObjectsWithTag("Patriot");
var thePatriot: GameObject = gameObject.FindGameObjectsWithTag(PatriotTagName);
if (thePatriot == null){
return ;
}
else{
targets = thePatriot.transform;
}
/*var PatriotPrefab = transform.gameObject.Find("Patriot");
for ( var target:GameObject in PatriotPrefab){
cameraScrolling.SetTarget (targets[1]);
}
}*/
private var windowRect : Rect = Rect (20, 20, 250, 40); // Make the onscreen GUI to let the player switch control between Lerpz and the spaceship. function OnGUI() { //Debug.Log(DoControlsWindow); // Make a popup window windowRect = GUILayout.Window (0, windowRect, DoControlsWindow, "Camera Controls");
// The window can be dragged around by the users - make sure that it doesn't go offscreen.
windowRect.x = Mathf.Clamp (windowRect.x, 0.0, Screen.width - windowRect.width);
windowRect.y = Mathf.Clamp (windowRect.y, 78.0, Screen.height - windowRect.height);
}
// Make the contents of the window function DoControlsWindow (windowID : int) { // Make the window be draggable in the top 20 pixels. GUI.DragWindow (Rect (0,0, System.Decimal.MaxValue, 20));
GUILayout.Label ("Press to changes target.");
// Let the player select the character
selected = GUILayout.Toolbar (selected, targetButtonNames);
// If the user has selected a new character, we'll send new SetControllable messages to turn on the other character.
// Then we'll change who the CameraScrolling script is tracking.
if (GUI.changed && targets[selected] != cameraScrolling.GetTarget ()) {
targets[selected].gameObject.SendMessage ("SetControllable", true, SendMessageOptions.DontRequireReceiver);
cameraScrolling.GetTarget().gameObject.SendMessage ("SetControllable", false, SendMessageOptions.DontRequireReceiver);
cameraScrolling.SetTarget (targets[selected]);
}
// Show a different instruction label depending on what was selected above.
switch (selected) {
case 0:
GUILayout.Label ("Player");
break;
case 1:
GUILayout.Label ("Player's Dog.");
break;
case 2:
GUILayout.Label ("Enemy to Kill.");
break;
}
}
// Ensure there is a CameraScrolling script attached to the same GameObject, as this script // relies on it.
Assets/Camera/CameraFocus.js(56,1): BCE0044: expecting }, found 'private'.
This script left above line to me which turn me confused for what should I do any Unities please HELP ME!
Fix your titel. That's not a question!!! Questions normally ends with a question-mark!
Answer by FrHaYwOrKs · Apr 21, 2011 at 10:55 AM
From line 49 to line 54 you have:
/*var PatriotPrefab = transform.gameObject.Find("Patriot");
for ( var target:GameObject in PatriotPrefab){
cameraScrolling.SetTarget (targets[1]);
}
}*/
You have commented a } that should be left uncommented, change that block of code to:
/*var PatriotPrefab = transform.gameObject.Find("Patriot");
for ( var target:GameObject in PatriotPrefab){
cameraScrolling.SetTarget (targets[1]);
}*/
}
And it should work fine...
Thanks u r right but this script still saying it cannot convert transform to transform[] what could I do, any ideas?
The script is right since in line 13 you are declearing var "targets : Transform[];// = new Transform[1];" so targets is of type Trasform[] and then in line 47 you state "targets = thePatriot.transform;" and thePatriot.transform is of type transform, so you are trying to assign a transform to a Transform[]. I haven't exa$$anonymous$$ated the script meaning at a logical level, just found out the current errors, the solution depends on what you need to do with that script! ^^
I were wanted to add the re-instantiation objects back to that position for it's transform[] but trying this out is hard.
The problem is that your "targets" variable is a list, so you cannot assign a single transform object to a list-of-transforms object. Try to assign you "thePatriot.transform" as an element of a list, ins$$anonymous$$d of assigning it to the whole list!
Could you please write an example for me I am sorry English wasn't my first language.. I do not understand what you mean by "as an element of a list".. ( even I could know the language but I might not know how could it be for Unity javascript so please Help me.)
Your answer
Follow this Question
Related Questions
Code Not Working. Any Ideas? 2 Answers
Script error. Please Help! 4 Answers
BCE0044: expecting ':' found ';' 1 Answer
Basic on collision play animation code not working 1 Answer
BCE0044: expecting :, found '=' 3 Answers