How can i add script when my characte pick up some thing added the time please any one can help me with that ? :?:
What do you mean by ‘added the time’? Is AddComponent() what you’re looking for?
Do you mean you want the character to get extra time to finish the level if he picks up a bonus object? If you are using a character controller then you can use the OnControllerColliderHit function to detect when it hits something. This gets passed an object that has information about the object you’ve run into. I would recommend you give the bonus object its own tag and check that to determine whether it has been hit:-
var levelTime: float;
function OnControllerColliderHit(hitObj: ControllerColliderHit) {
if (hitObj.gameObject.tag == "TimeBonus") {
levelTime += 5; // eg, for a 5 second bonus.
Destroy(hitObj.gameObject);
}
}
This also destroys the bonus object after it has been touched.