Skip to content

Instantly share code, notes, and snippets.

@blackstuend
Created October 16, 2018 08:43
Show Gist options
  • Save blackstuend/d10be671067f5cc8d41f14f5f86757d9 to your computer and use it in GitHub Desktop.
Save blackstuend/d10be671067f5cc8d41f14f5f86757d9 to your computer and use it in GitHub Desktop.

delCube.cs

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

public class delcube : MonoBehaviour {
    public Text textUI;
    // Use this for initialization
    void Start () {

}
    	
	// Update is called once per frame
	void Update () {
			if(transform.position.y<=0)
			{
				Debug.Log("finish");
                renew.score += 10;
                Destroy(gameObject);
			}
	}
}

CreateCube.cs

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

public class renew : MonoBehaviour {
    public GameObject cubeBlue;
    private float timer;
    public static int score = 0;
    public Text text;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        text.text = score.ToString();
        if (timer > 3)
        {
            Vector3 pos = new Vector3(Random.Range(-3, 3), 3, Random.Range(-3, 3));
            Instantiate(cubeBlue, pos, Quaternion.identity);
            timer = 0;
        }
        else
            timer += Time.deltaTime;
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment