using UnityEngine;
using System.Collections;
public class StartTheBall : MonoBehaviour {
float cacheX;
float cacheY;
float cacheZ;
Quaternion cacheRotation;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
cacheX = transform.position.x;
cacheY = transform.position.y;
cacheZ = transform.position.z;
cacheRotation = transform.rotation;
if (Input.GetKey(KeyCode.Space))
{
Destroy(this.gameObject);
}
}
void OnDestroy() {
Debug.Log("Destroyed!");
GameObject ball = (GameObject)Instantiate(Resources.Load("PlayerBall"), new Vector3(cacheX, cacheY, cacheZ), cacheRotation);
}
}
Compiles, the game runs, but then the object is destroyed, instead of creating the premade object, it gives me that:
ArgumentException: The prefab you want to instantiate is null.
UnityEngine.Object.CheckNullArgument(System.Object arg, System.String message) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:103)
The problem, 100% sure is at this line:
GameObject ball = (GameObject)Instantiate(Resources.Load(“PlayerBall”), new Vector3(cacheX, cacheY, cacheZ), cacheRotation);
I would appreciate any help!