Ive tried c# and javascript but for some reason this coin will not dissapear or add to my score when i enter the print value any help i would post my script but it reads no errors and still doesnt even work i used box collider on coin with simple onTriggerEnter function and added the destroy(collider.gameobject) to make the coin go away and nothing ever happens any help please…1287083–58624–$Player_Money.js (129 Bytes)1287083–58623–$Collection.js (179 Bytes)
function OnTriggerEnter()
Capitalize the O in On. It is case-sensitive. Also make sure the collider is set a trigger in the inspector.
Nope i even just tryed with collision and watched a youtube video it will not work…im dyin here the frustration is building
even the most simple occurence of the coin destroying itself wont occur and i get no errors on console
Do you mark the checkbox that says “Is Trigger” for the gameobject that has the OnTriggerEnter script?
The only other option is that you do not have either a CharacterController or a RigidBody on the object that is interacting with the trigger…
sharing the code would help
As what I remember, you need 1 of the objects to have a rigidbody component to use the onTrigger functions
i tried it this other way that seemed the easiest still no luck but here is the code…
var Player : Transform;
function OnCollisionEnter(collision : Collision)
{
if(collision.Transform == Player)
{
Destroy(gameObject);
}
had all my braces though keep in mind…
//Add the Player tag to player. On the coin click is trigger. This needs to be on the coin.
function OnTriggerEnter (other : Collider) {
if(other.GameObject.tag=="Player")
{
Destroy(gameObject);
}
}
now it says gameobject is not a member of unityengine.collider
You do not need to check tags. The coin needs a collider that is set to IsTrigger(). The player needs a collider and a rigidbody. Then the OnTriggerEnter() function on a script on the coin will trigger correctly every time. You have set something up wrong. Make sure you have spelled everything correctly. Make sure you you have the correct capital letters in the correct spaces. And finally read the documentation again.
Here, you can use my setup. It works great!
This one manages the collecting of the coins:
enum PickupType { Health = 0, FuelCell = 1 }
var amount = 1;
var sound : AudioClip;
var soundVolume : float = 2.0;
var CoincounterComponent: Component;
var pickupType = PickupType.Coin;
private var used = false;
function Start ()
{
// do we exist in the level or are we instantiated by an enemy dying?
mover = GetComponent(DroppableMover);
}
function ApplyPickup (playerStatus : ThirdPersonStatus)
{
CoincounterComponent = GetComponent("Coincounter");
switch (pickupType)
{
case PickupType.Coin:
playerStatus.FoundItem(amount);
break;
// A switch...case statement may seem overkill for this, but it makes adding new pickup types trivial.
case PickupType.Coin:
playerStatus.FoundItem(amount);
break;
}
return true;
}
function OnTriggerEnter (col : Collider) {
Coincounter.pointCoin +=1;
if(DroppableMover DroppableMover.nabled) return;
var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus);
//* Make sure we are running into a player
//* prevent picking up the trigger twice, because destruction
// might be delayed until the animation has finished
if (used || playerStatus == null)
return;
if (!ApplyPickup (playerStatus))
return;
used = true;
// Play sound
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
// If there is an animation attached.
// Play it.
if (animation animation.clip)
{
animation.Play();
Destroy(gameObject, animation.clip.length);
}
else
{
Destroy(gameObject);
}
}
// Auto setup the pickup
function Reset ()
{
if (collider == null)
gameObject.AddComponent(BoxCollider);
collider.isTrigger = true;
}
@script RequireComponent(SphereCollider)
@script AddComponentMenu("Third Person Props/Pickup")
And this one will display your total coins on screen:
static var pointCoin : int = 0;
public var coinTotal: int ;
//Manger object called "gameManager" script called "GameManager".
function Awake () {
DontDestroyOnLoad (transform.gameObject); //This keeps the manager object from being destroyed.
}
function Start () {
//Manger object called "gameManager" script called "GameManager".
GameHUDComponent = GetComponent(GameHUD);
}
function OnGUI() {
;
GUI.Box (Rect (8, 10, 120, 60), "Coins: " + pointCoin);
}
Hope that helps!
THANKS MAN! was losing it i gotta short fuse…