Skip to content

Instantly share code, notes, and snippets.

@mikamikuh
Last active December 13, 2015 20:09
Show Gist options
  • Select an option

  • Save mikamikuh/4968326 to your computer and use it in GitHub Desktop.

Select an option

Save mikamikuh/4968326 to your computer and use it in GitHub Desktop.
6-2. 景品によって得点を加算する
using UnityEngine;
using System.Collections;
public class GameTrigger : MonoBehaviour {
// スコアの合計
public int totalScore = 0;
void OnTriggerEnter (Collider col)
{
// 景品コンポーネントを取得
ItemObject obj = col.gameObject.GetComponent<ItemObject>();
if(obj != null) {
// 取得出来たら(景品だったら)スコアを加算
totalScore += obj.score;
}
Destroy (col.gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment