Created
April 12, 2019 23:40
-
-
Save tnoborio/a10c9bfa5615e83a6ca8e67cf3967827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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