Skip to content

Instantly share code, notes, and snippets.

@tnoborio
Created April 12, 2019 23:40
Show Gist options
  • Save tnoborio/a10c9bfa5615e83a6ca8e67cf3967827 to your computer and use it in GitHub Desktop.
Save tnoborio/a10c9bfa5615e83a6ca8e67cf3967827 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameSystem : MonoBehaviour
{
public Text text;
public int score = 0;
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
var tapPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var collition2d = Physics2D.OverlapPoint(tapPoint);
if (collition2d)
{
var hitObject = Physics2D.Raycast(tapPoint, -Vector2.up);
if (hitObject)
{
Debug.Log("hit object is " + hitObject.collider.gameObject.name);
if (hitObject.collider.gameObject.name == "mogura"
&& hitObject.collider.gameObject.GetComponent<SpriteRenderer>().enabled)
{
score += 10;
text.text = "スコア: " + score;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment