Asked this is "awnsers" section but im not sure if i should have put it there or here..

this is the code that i have, and i am almost positive that I have the same as he shows on the screen, but i am getting these errors.. error on line 18, 25 saying argument #1 cannon convert object espression to type unityEngine.object. another error says the best overload method match for unity engine object dontdestroyonload(unity.Engine.object) has some invalid arguments, and finally expression denotes a type where a variable value or method group was expected.

 using UnityEngine;
using System.Collections;
public class GameControl : MonoBehaviour {
     public static GameControl control;
     public  float fish;
     public  float fishPerTap;

     void Awake ()
     {
         if (control == null)
         {
             DontDestroyOnLoad (GameObject);
             control = this;
         }
             else if (control != this)
             {
                 Destroy(gameObject);
             }
     }

}

my question is if you can see where i am messed up on this code. it seemed pretty simple. my first thought is that i was missing a using " fill in the blank" at the top, but he didnt have anything extra added.

I have moved all the variables and connected them through this code, but the errors keep me from running the program. I keep looking over it, and i feel like it looks ok. It matches the video exactly, except of course for the 2 of my own variables put in there.

At a glance I think you're trying to pass the class itself on line 12 rather than the actual game object. Try this instead.

DontDestroyOnLoad(transform.gameObject);

thank you, that is what i was doing wrong i worked it out just a bit ago i capitalized the g .. woops . thanks :)

Inside a MonoBehaviour just gameObject is sufficient, as in

DontDestroyOnLoad(gameObject);

or even

DontDestroyOnLoad(this);
1 Like