I am an artist and I can't figure out the new activate/deactivate scripting method for gameObjects. I just can't upgrade to the new method, nothing works. Here's what I have before unity 4.x
//This script handles targets, being hit, shrinking and expanding, and the 3 score types.
#pragma strict
private var _thisTransform:Transform; //Used to hold this object's transform for quicker access
var _goodScore:int = 10; //The score value of a good hit
var _greatScore:int = 20; //The score value of a great hit
var _bullseyeScore:int = 40; //The score value of a bullseye
internal var _scaleTarget:float = 2; //What should the scale of this target be?
internal var _targetHit:boolean = false; //Has this target been hit?
function Start ()
{
_thisTransform = transform; //cache this transform for quicker access
}
function Update ()
{
if ( _targetHit == true)
{
//collision detected
//or destruction animation
_thisTransform.gameObject.SetActiveRecursively(false); //Deactivate this object
_thisTransform.parent.parent.GetComponent(level).checkTargets(); //Check if we hit all the targets in the le
}
/* //If we haven't scaled this object to its target scale, keep scaling it
if ( Mathf.Abs(_thisTransform.localScale.x - _scaleTarget) > 0.1 )
{
//Smoothly scale this object to its target scale
_thisTransform.localScale.x -= (_thisTransform.localScale.x - _scaleTarget) * 0.2;
_thisTransform.localScale.y -= (_thisTransform.localScale.y - _scaleTarget) * 0.2;
}
else if ( _thisTransform.localScale.x != _scaleTarget ) //If we reached close enough to the target scale, set it to the exact target scale
{
//Set this object to the exact target scale
//var pos: Vector3 = Vector3(Random.Range(-0.3, 0.3), Random.Range(-0.3, 0.3), 0);
_thisTransform.localScale.x = _scaleTarget;
_thisTransform.localScale.y = _scaleTarget;
//_thisTransform.position = pos;
}
//If this object's scale is small enough, deactivate it, and check if we hit all the targets in the level
if ( _thisTransform.localScale.x <= 0.5 && _thisTransform.gameObject.active == true )
{
_thisTransform.gameObject.active = false; //Deactivate this object
_thisTransform.parent.parent.GetComponent(level).checkTargets(); //Check if we hit all the targets in the level
}*/
}
↧