Why is simple script not working?

Can someone tell me what I’m doing wrong? I’m new to coding, so I’m sure I’ve overlooked something. Within the editor, I dragged the code onto my trigger object and set the correct asset within my scene as the “thwomp” GameObject. I’ve also set the correct numeric values for var changeScale. I just want to scale the “thwomp” object up and down while in the trigger.

#pragma strict

var changeScale:Vector3;
var thwomp:GameObject;

function Awake(){
collider.isTrigger=true;
}

//function OnTriggerStay(col:Collider){
//thwomp.transform.localScale += changeScale;
//}

function OnTriggerStay(col:Collider){
if(Input.GetButton(“Fire1”))
{
thwomp.transform.localScale += changeScale;
}
if(Input.GetButton(“Fire2”))
{
thwomp.transform.localScale += (changeScale*-1);
}
}

What is your error?

Change

var thwomp:GameObject;

to

var thwomp : Transform;

also, please use [ code ] [ / code ] tags (no spaces in [ ])

Object collider trigger must not be the same…
you using what for the two Object?box collider,mesh collider,character controller…

Does either one of the object has a rigidbody? If you use two static colliders (collider w/o rigidbody attached), they won’t trigger each other.

Consult the documentation on Box/Mesh/Any Collider, there is a collision matrix on the bottom.

Edit:
Also do not process input in OnCollide/OnTrigger methods, always do it in Updates and use OnCollide to set a flag.

I’m using a cube for the trigger and a mesh for the affected object. Actually I noticed now that the code is working, however it doesn’t affect what’s in the scene. It only affects the prefab within the Project hierarchy. For example, I am trying to scale the mesh while inside the trigger. Nothing happens on screen but if I go into the project window and drag that same prefab into the scene I notice that the scaling I just applied affected the prefab and the prefab is now larger than it was before. Why would this happen? Why would my scaling affect the prefab and not the actual asset within the scene?

That’s because you are directly interacting with the prefab. If the script is in the same object that you want to scale you should just use “transform.localScale” instead of “thwomp.transform.localScale”. Or instantiate it and keep the reference in a variable

Thank you, everyone. Your advice helped. I used " var thwomp:Transform" instead and that fixed it.