Help with a job for the school, I can not detect a "public class"

0

As part of a project for the school I am trying to create an Idle / Clicker game, (With Unity) and I am learning the most basic programming, I am studying and that, but as I have not had much time , because I am being guided by a video of a type on the internet.

I'm just starting to create the interface and the buttons, but I've been docked in something fundamental and that will surely be very simple so I have 2 Scripts one to control the "gold" and one to control the improvements, with which You can earn more gold.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Click {

    public UnityEngine.UI.Text goldDisplay;
    public int gold = 0;
    public int goldperclick = 1;

    void Update() {
        goldDisplay.text = "Gold: " + gold;
    }

    public void Clicked () {
        gold += goldperclick;
    }

}

I do not know why it came out that way but well, that's the first script

And then

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeManager {
    public Click click;
}

Here does not detect the "Click" when I put public

    
asked by Francesco Carlevarino 08.09.2017 в 03:24
source

1 answer

1

The C # Script created in Unity3D must inherit from Monobehavior, to be added to a GameObject of the scene as a component.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Click : MonoBehaviour
{
    public Text goldDisplay;
    public int gold = 0;
    public int goldperclick = 1;

    void Update() {
        goldDisplay.text = "Gold: " + gold;
    }

    public void Clicked () {
        gold += goldperclick;
    }

}

With this you can use methods like "Update".

and in the other script it would be something like.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeManager : MonoBehaviour 
{
    Click click;

    Awake()
    {
      click = FindGameObjectWithType<Click>();
    }
}

link

    
answered by 22.09.2018 в 01:04