キャラを破壊する


キャラを破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerShot : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip effectSound;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
GameObject target = hit.collider.gameObject;
if (target.tag == "Chara")
{
Destroy(target.gameObject);
GameObject effect = Instantiate(effectPrefab, target.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
AudioSource.PlayClipAtPoint(effectSound, Camera.main.transform.position);
}
}
}
}
}




【2019版】AR_Project(全9回)
| 1 | Vuforiaの初期設定を行う |
| 2 | キャラクターをAR鑑賞する |
| 3 | ★チャレンジ課題 |
| 4 | ARシューティングゲームの開発 |
| 5 | キャラを破壊する |
| 6 | オリジナルのカーソルを作成する |
| 7 | カウンターを作成する |
| 8 | ★チャレンジ課題 |
| 9 | ★チャレンジ課題 |


キャラを破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerShot : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip effectSound;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
GameObject target = hit.collider.gameObject;
if (target.tag == "Chara")
{
Destroy(target.gameObject);
GameObject effect = Instantiate(effectPrefab, target.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
AudioSource.PlayClipAtPoint(effectSound, Camera.main.transform.position);
}
}
}
}
}




キャラを破壊する