문제

so I was reading the unity 3d script reference. Link below http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

I wanted to test the example

    using UnityEngine;
    using System.Collections;

public class Example : MonoBehaviour {
    public Transform explosionPrefab;
    void OnCollisionEnter(Collision collision) {
        ContactPoint contact = collision.contacts[0];
        Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
        Vector3 pos = contact.point;
        Instantiate(explosionPrefab, pos, rot) as Transform;
        Destroy(gameObject);
    }
}

but I receive the error

Parse error: Only assignments, call, increment, decrement, await, and new object

at line 20[Instantiate(explosionPrefab, pos, rot) as Transform;]

Could someone please explain to me why I get such an error? and how I could fix it? Thanks.

도움이 되었습니까?

해결책

Change this line

Transform transform = Instantiate(explosionPrefab, pos, rot) as Transform;

Alternatively remove the as Transform part if you don't need the instance

Instantiate(explosionPrefab, pos, rot) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top