When I Hit or Destroy the object , one “money” or more will be generated,
it effect such as the following website :
http://www.youtube.com/watch?feature=player_embedded&v=0TtxYkYAcVY#!(25s~42s)
http://www.youtube.com/watch?feature=player_embedded&v=Ynf4kVS3Z_c (6s~10s)
How to write that? Can give some prototype(package) or suggest? thanks
If you have object A, lets call it the player, object B, lets call it box, and object C, letts call it coin.
When object A hits object B if you have attached rigid bodies or coliders to your object certain functions will get called:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html
That is the one that you will need in this case.
So when they hit that function will be called with the Collision parameter. That Collision parameter can then be used to identify the object that was hit through:
http://unity3d.com/support/documentation/ScriptReference/Collision-gameObject.html
You can then destroy that object and in its place use the Instantiate function:
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
If you store a public gameobject variable on your script you can then use that to instantiate the coin prefab in the correct place.
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject coinObject;
void OnCollisionEnter(Collision collision)
{
Debug.Log("collision");
Instantiate(coinObject, collision.gameObject.transform.position, collision.gameObject.transform.rotation);
Destroy(collision.gameObject);
}
}