Simple Script Need a little help :D

Hello All and as usual always a pleasure :smile:

I have a enemyCount Script:

static var enemyCount : int = 0;

function Update () 
{
	if(enemyCount < 1)
	{
		//Instantiate prize and open door
		print("Ok Now Open The Door!");
		DoorTrigger1.openDoors = true;//this will open all doors in the array 	
	}
	if(enemyCount > 0)
	{
		print("The Enemy Count is" + "" + enemyCount);	
	}
}

When the enemy count is zero I want the doors of the room to open and here is the script for that which works when I use the door as a trigger.

static var openDoors : boolean = false;
var doors : GameObject;

function OnTriggerEnter (enter :Collider)
{
	if(enter.gameObject.name == "Robot")
	{
		print("Robot entered");
		OpenDoor();
	}	
}
function OpenDoor()
{
	if(openDoors == true)
	{
		doors.transform.position.y += 2.5;
	}	
}

But I would like to open the door without a trigger just using the enemyCount and this is where Im at but it dosent seem to be working, And heres the trouble script. I get the above debug log (“Ok Now Open The Door!”); which is working but Im stumped and need to figure out what Im doing wrong?

static var openDoors : boolean = false;
var doors : GameObject;

function update()
{
	if(openDoors == true)
	{
		doors.transform.position.y += 2.5;	
	}	
}

(I know if it was working the door would probably keep on rising 2.5 because its in the update but Id like to atleast try and get it working before I worry about that)

Where is DoorTrigger1 created?
I’m assuming you left out some code and that DoorTrigger1 is referencing your Doors.
If this is true, I don’t see why this doesn’t work.

To test this, remove the “if(openDoors == true)” from the Door’s update function. If it moves, then you know that openDoors is not being changed correctly.

Hey Dman,

Thanks for the suggestion. So I removed the if statement and I also removed the static variable to what’s below and its still not moving. So Im thinking… maybe I cant access another object this way? or something so with the script below I created an empty game object attached the script below and created a cube, then put the cube as the gameObject varable doors. Pressed Play and nothing?

var doors : GameObject;

function update()
{
	doors.transform.position.y += 2.5;	
		
}

So any reason why this wouldn’t work?

it will work fine with a trigger but just being in the Update function theres nothing so maybe something has to trigger it? I was hoping to use the enemyCount but… lol

The fact that it doesn’t work in the update function means that its not the trigger that isn’t working, but rather the way you are opening the door. Changing the way that you trigger the opening of the doors shouldn’t change the outcome. There is probably something you missed when transferring the code over.

Create a new script with only

function update()
{
    transform.position.y += 2.5;
}

And attach that to a cube. If this works, then you are referencing your array of doors incorrectly.

Ok such a simple script I created the new script as suggested then created a cube attached the script to the cube when I press play… ahhh… The cube still sits there? It dosent get much simpler than that so Back to the original question Why would this not work? It cant get broken down anymore. But How about a new question?

Is there another way to move something it without using a trigger?

function update()
{
    transform.position.y += 2.5;
}

Wowowow

I shut down unity then decided to give it one more try I restarted and presto the cube climbs in the air in increments of 2.5 YAY!

Ok now time to start building it back up :slight_smile: I’ll take out the += and it should stop there :slight_smile:

I guess Unity just needed a break lol

That is the way to move something without a trigger.

Everything has the potential to be a trigger. The only thing that makes them one is how you decide to use them.

Because that script doesn’t work, I would advise you to move it a different way.

A quick search brings up transform.translate which should give you the functionality you want.
http://unity3d.com/support/documentation/ScriptReference/Transform.Translate.html

Some more helpful links:

Lerp: Smooths movement.
http://unity3d.com/support/documentation/ScriptReference/Vector3.Lerp.html

Clamp: Limits movement.
http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Vector3.Clamp

Use the transform.translate function, attach that to a cube, and post back with your results. If it still doesn’t work, post your exact code.

EDIT: Looks like you got it working. These are still relevant links that are worth checking out.

Thanks Dman Greatly appreciated Im going to use the translate for its smoothness. I was just boggled as to why it wouldn’t work and I guess the machine just needed a break lol

But Thanks for hanging in there to help find a solution, GREATLY APPRECIATED! Thank You!!!