Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Problem assigning parentin C#

$
0
0
Hello, I'm trying something very simple, an electron orbiting an atom... my C# code is the following public class AtomScript : MonoBehaviour { public int electrones; public Transform electronPrefab; // Use this for initialization void Start () { GameObject clone = Instantiate(electronPrefab, transform.position * 1.5f, transform.rotation) as GameObject; clone.transform.parent = transform; } // Update is called once per frame void Update () { } } And it throws an exception NullReferenceException: Object reference not set to an instance of an object AtomScript.Start () (at Assets/AtomScript.cs:12) Line 12 is clone.transform.parent = transform; I don't understand where is the error. If I write this code in JS it works without any problem. :(

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>