Search Unity

Instantiate on collision warning

Discussion in 'Scripting' started by yangmeng, Jun 8, 2007.

  1. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    I am getting the following warning when trying to instantiate a prefab upon a collision with an object:
    "Number of parameter does not match expected count."
    Here is the script:
    Code (csharp):
    1. function OnCollisionEnter (object) {
    2.     if (object.transform.name == "proj(Clone)") {
    3.             var contact = object.contacts[0];
    4.             var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
    5.             var pos = contact.point;
    6.             Instantiate(prefab1, pos, rot);
    7.     }
    8. }
    Any ideas what's going wrong?
     
  2. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    the OnCollisionEnter function wants to be passed a Collision, not a GameObject.

    Replace the first two lines with:

    Code (csharp):
    1. function OnCollisionEnter (collision : Collision) {
    2.  if (collision.collider.gameObject.name == "proj(Clone)") {
     
  3. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    Great. Thanks Yoggy!