- Home /
Script does not behave the way it should?
Hallo. I have been trying to fix the problem for some time, but I simply can not. The point is to enable the player to navigate around a 3 point room, but it just does not behave in a logical manner. Could anyone please help me with this?
I know that this is a large code, but you can ignore a large part of it, which is marked.
// Variable declarations.
var room = 1;
var inroom = 1;
var roomfront : Transform;
var roomsfront : GameObject;
var roommed : Transform;
var roomsmed : GameObject;
var roomback : Transform;
var roomsback : GameObject;
var piano : Transform;
var walltexture: Material [];
var walltexturetwo: Material [];
var MainCamera : Transform;
var MainCameraOb : GameObject;
var MovementOfCam = 0;
static var InWhatPlace = 0;
var cameraStart : Vector3;
var cameraAngles: Vector3;
var cameraPosOne: Vector3;
var cameraPosTwo: Vector3;
function Update ()
{
// You can ingnore the code from here........................................................................
// This was made some time ago for testing in an infinite map loop.
if (Input.GetKeyDown("space") && inroom == 1)
{
roomsfront.renderer.materials [0] = walltexture[(Random.Range(1, 4))];
roomsmed.renderer.materials [2]= walltexturetwo[(Random.Range(1, 8))];
roomback.position = Vector3 (-29.91534, 9.142463, (-94.81549));
MainCamera.position = Vector3 (-25.54817, 14.8314, (-72.66501 + 7.72372));
piano.position = Vector3 (-32.32533, 10.80438, -72.66501);
inroom = 2;
}
else if (Input.GetKeyDown ("space") && inroom == 2)
{
roomsback.renderer.materials [0]= walltexture[(Random.Range(1, 4))];
roomsmed.renderer.materials [2]= walltexturetwo[(Random.Range(1, 8))];
MainCamera.position = Vector3 (-25.54817, 14.8314, (-94.81549 + 7.72372));
piano.position = Vector3 (-32.32533, 10.80438, (-94.81549));
roommed.position = Vector3 (-29.91534, 9.142463, (-116.96597));
inroom = 3;
}
else if (Input.GetKeyDown("space") && inroom == 3)
{
roomsmed.renderer.materials [0]= walltexture[(Random.Range(1, 4))];
roomsmed.renderer.materials [2]= walltexturetwo[(Random.Range(0, 8))];
MainCamera.position = Vector3 (-25.54817, 14.8314, (-50.51353 + 7.72372));
roomfront.position = Vector3 (-29.91534, 9.142463, -72.66501);
roommed.position = Vector3 (-29.91534, 9.142463, -50.51353);
roomback.position = Vector3 (-29.91534, 9.142463, -28.36128);
piano.position = Vector3 (-32.32533, 10.80438, -50.51353);
inroom = 1;
}
// To here...................................................................................................
//There are arrows in the scene, and they return 'Arrows.ToMoveTheCam' 1 or 2. 1 for the Keypad area and 2 for the Piano area.
// There is also a keypad button, 'cancel', which returns ButtonPressed = 10. Otherwise these are simple key presses.
if (((Input.GetKeyDown("a") && InWhatPlace == 1) || (Input.GetKeyDown("a") && InWhatPlace == 2)) || (KeyOfPad.ButtonPressed == 10))
{
KeyOfPad.ButtonPressed == 0;
InWhatPlace = 0;
iTween.MoveTo(MainCameraOb,Vector3(-24.07,13.57,-43.53),5);
iTween.RotateTo(MainCameraOb, Vector3(19.01, -142.5, 0), 7);
}
if ((Arrows.ToMoveTheCam == 1) || (Input.GetKeyDown("a") && InWhatPlace == 0) || (Input.GetKeyDown("a") && InWhatPlace == 2))
{
InWhatPlace = 1;
iTween.MoveTo(MainCameraOb,Vector3(-28.94,12.33,-59.96),5);
iTween.RotateTo(MainCameraOb, Vector3(0, 180, 0), 7);
Arrows.ToMoveTheCam = 0;
}
if ((Arrows.ToMoveTheCam == 2) || (Input.GetKeyDown("d") && InWhatPlace == 1) || (Input.GetKeyDown("d") && InWhatPlace == 0))
{
InWhatPlace = 2;
iTween.MoveTo(MainCameraOb,Vector3(-28.40594,12.76859,-49.80258),5);
iTween.RotateTo(MainCameraOb,Vector3(59.25, -90, 0), 6);
Arrows.ToMoveTheCam = 0;}
}
// Give the error 4 times.
//UnassignedReferenceException: The variable MainCameraOb of 'MainScript' has not been assigned.
//You probably need to assign the MainCameraOb variable of the MainScript script in the inspector.
//iTween.Launch (UnityEngine.GameObject target, System.Collections.Hashtable args) (at Assets/Plugins/iTween.cs:6740)
//iTween.MoveTo (UnityEngine.GameObject target, System.Collections.Hashtable args) (at Assets/Plugins/iTween.cs:1448)
//iTween.MoveTo (UnityEngine.GameObject target, Vector3 position, Single time) (at Assets/Plugins/iTween.cs:1347)
//MainScript.Update () (at Assets/Other/MainScript.js:152)
Comment
Answer by Bunny83 · Apr 02, 2012 at 01:14 PM
"You probably need to assign the MainCameraOb variable of the MainScript script in the inspector"
...
Your answer
Follow this Question
Related Questions
iTween FadeTo() problem 1 Answer
iTween "No appropriate version" solvable? 1 Answer
iTween.ValueTo doesn't work? 0 Answers
error CS0266: Cannot implicitly convert type `UnityEngine.Component' to `iTween'. 1 Answer
Animation Not Working! 1 Answer