Search Unity

Create prefab to scene script works, but Unity gives an error report every frame

Discussion in 'Scripting' started by matias-e, Feb 25, 2015.

  1. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    So, I wanted to create a script that creates a prefab of my choice to a semi-random place and it works. However, Unity pushes out the following error report every frame:

    I have made the transformable object public so I can drop the prefab into the script in Unity editor. I have dropped my prefab there and when I press play it spawns those objects every frame.

    Here's the code.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class enemyController : MonoBehaviour {
    5.  
    6.     public Transform collect00;
    7.  
    8.     int collectAmt = 0;
    9.     private Vector3 collectPos;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.  
    14.         transform.position = collectPos;
    15.  
    16.         transform.position = new Vector3(Random.Range(-100.0f, 100.0f),
    17.                                           Random.Range(1.6f, 100.0f),
    18.                                           Random.Range(-100.0f, 100.0f));
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update () {
    23.  
    24.         if(collectAmt < 30)
    25.         {
    26.  
    27.             var go = Instantiate(collect00, collectPos, Quaternion.identity);
    28.      
    29.  
    30.         collectAmt = collectAmt + 1;
    31.  
    32.         }
    33.  
    34.  
    35.     }
    36. }
    What could be the problem here? Why is Unity giving me this error report?
     
  2. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Nevermind.. I had another instance of this script dropped within Unity, whoops.