ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2020ǯ11·î07Æü(ÅÚ) 16:23:10ÍúÎò
¡¡°Û¤Ê¤ë¿§¤Î¥Ö¥í¥Ã¥¯¤ò¿·¤·¤¯£±¤Äºî¤ê¡¢Âѵ×ÅÙ¡ÊÇ˲õ¤·¤Ë¤¯¤µ¡Ë¤òÄɲ䷤ƥ²¡¼¥àÀ¤òÁý²Ã¤µ¤»¤Þ¤¹¡£
¤Þ¤¿¡¢¤¹¤Ç¤Ë¤¢¤ë¥Ö¥í¥Ã¥¯¤È¤Ï°Û¤Ê¤ëÅÀ¿ô¤ò»ý¤¿¤»¤ë¤³¤È¤Ç¡¢¥×¥ì¥¤¥ä¡¼¤ËÇ˲õ¤·¤Ë¤¯¤¤¤¬ÅÀ¿ô¤¬¹â¤¤¡¢¤È¤¤¤¦¥·¥¹¥Æ¥à¤òÄ󼨤Ǥ¤Þ¤¹¡£
¡¡°Ê²¼¤Î¼ê½ç¤Ç¼ÂÁõ¤·¤Þ¤¹¡£
£±¡¥Box¥×¥ì¥Õ¥¡¥Ö¤òÍøÍѤ·¤Æ¡¢¿·¤·¤¤Box¡ÊHardBox¡Ë¤òºîÀ®¤·¤Æ¥×¥ì¥Õ¥¡¥Ö¤Ë¤·¤Þ¤¹¡£ £²¡¥Destroyer¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Þ¤¹¡£ £³¡¥¤µ¤é¤Ë¥Ö¥í¥Ã¥¯¤Î¼ïÎà¤òÁý¤ä¤·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢£±¤Î¼ê½ç¤ò·«¤êÊÖ¤·¤Þ¤¹¡£
¡¡¥Ò¥¨¥é¥ë¥¡¼Æâ¤Ë¡¢Prefabs¥Õ¥©¥ë¥À¤Ë¤¢¤ëBox¥×¥ì¥Õ¥¡¥Ö¡¦¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥É¥é¥Ã¥°¡õ¥É¥í¥Ã¥×¤·¤Þ¤¹¡£
¤½¤Î¸å¡¢¤³¤ÎBox¤Î̾¾Î¤òÊѹ¹¤·¤Þ¤¹¡£¡ÊHardBox¡¢¤Ê¤É¡Ë
¤³¤ÎBox¤ò¸µ¤Ë°Û¤Ê¤ë¿§¤ÎBox¤òºîÀ®¤·¤Æ¤¤¤¤Þ¤¹¡£
¡¡Materials¥Õ¥©¥ë¥À¤ÎÃæ¤Ç±¦¥¯¥ê¥Ã¥¯¤ò¤·¤Æ¡¢create -> Material¤òÁªÂò¤·¡¢¹¥¤¤Ê̾¾Î( HardBoxMaterial ¤Ê¤É)¤òÉÕ¤±¤Æ¿·¤·¤¤¿§¤òºîÀ®¤·¤Þ¤¹¡£
¤½¤Î¿·¤·¤¤Material¤òHardBox¤Ë¥É¥é¥Ã¥°¡õ¥É¥í¥Ã¥×¤·¤Þ¤¹¡£¤³¤ì¤Ç¿§¤¬Êѹ¹¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡HardBox¤ò¥Ò¥¨¥é¥ë¥¡¼¤è¤ê¡¢Prefabs¥Õ¥©¥ë¥À¤Ë¥É¥é¥Ã¥°¡õ¥É¥í¥Ã¥×¤·¤Þ¤¹¡£
¥Ò¥¨¥é¥ë¥¡¼¤ÎHardBox¤Îʸ»ú¤Î¿§¤¬ÀÄ»ú¤Ë¤Ê¤ì¤Ð̵»ö¤Ë¥×¥ì¥Õ¥¡¥Ö²½¤Ç¤¤Æ¤¤¤Þ¤¹¡£
¤½¤Î¸å¡¢¥Ò¥¨¥é¥ë¥¡¼¤è¤êºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡Â³¤¤¤Æ¡¢Destroyer.cs¤ò½¤Àµ¤·¡¢Âѵ×ÎϤäSE¤Ê¤É¤òÄɲä·¤Þ¤¹¡£
Destroyer.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Destroyer : MonoBehaviour { public int point; // ÆÀÅÀ ¡¡¡¡public GameObject masterObj;¡¡ // "Master"¤È¤¤¤¦Ì¾Á°¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥ÈÍÑ public int initHp; // Âѵ×ÎϤκÇÂçÃÍ <- ¤³¤³¤«¤é private int currentHp; // Âѵ×ÎϤθ½ºßÃÍ public AudioClip hitSE; // Ç˲õ¤µ¤ì¤Ê¤¤¾ì¹ç¤ÎSE public AudioClip destroySE; // Ç˲õ¤µ¤ì¤¿¾ì¹ç¤ÎSE void Start () { // Box¤ÎÂѵ×ÎϤò½é´ü²½¤·¤Þ¤¹¡£(¸½ºßÃÍ¡áºÇÂçÃͤˤ¹¤ë) this.currentHp = initHp; } private void OnCollisionEnter(Collision collision) { // ¥Ü¡¼¥ë¤¬ÀÜ¿¨¤¹¤ë¤¿¤Ó¤Ë¡¢Âѵ×ÎϤò1¤º¤Ä¸º¤é¤·¤Þ¤¹¡£ this.currentHp -= 1; // ²õ¤ì¤ë¾ì¹ç if (this.currentHp <= 0) { ¡¡¡¡¡¡¡¡¡¡¡¡// Ç˲õ¤µ¤ì¤ëSE¤òºÆÀ¸ AudioSource.PlayClipAtPoint(DestroySE, transform.position); // »Ä¤ê¤Î¥Ö¥í¥Ã¥¯¿ô¤ò£±¤Ä¸º¤é¤¹ masterObj.GetComponent<GameMaster>().boxNum--; // ¥¹¥³¥¢¤ò²Ã»»¤¹¤ë FindObjectOfType<Score>().AddPoint(point); // ¤³¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡Ê¥Ö¥í¥Ã¥¯¡Ë¤òÇ˲õ¤¹¤ë¡¡¡¡¡¡¡¡ Destroy(this.gameObject); } // ¤Þ¤À²õ¤ì¤Ê¤¤¾ì¹ç else { // ¥Ü¡¼¥ë¤òÄ·¤ÍÊÖ¤¹SE¤òºÆÀ¸ AudioSource.PlayClipAtPoint(hitSE, transform.position); } < - ¤³¤³¤Þ¤Ç } }
¡¡public¤ÇÍÑ°Õ¤·¤¿ÊÑ¿ô¤¬Â¿¤¤¤Î¤Ç¡¢¿ôÃͤÎÆþÎϤäSE²»¸»¥Õ¥¡¥¤¥ëÍѤΥ³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲ䷤ơ¢¥¢¥µ¥¤¥ó¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£
¡¡¤Þ¤¿¡¢SE¤Ë¤Ä¤¤¤Æ¤Ï¡¢Destroyer ¥¹¥¯¥ê¥×¥ÈÆâ¤Ë HitPlaySound ¤Îµ¡Ç½(Ç˲õ»þ¤ÈÈóÇ˲õ»þ¤Çʬ´ô¤¬È¯À¸¤¹¤ë¤¿¤á¡Ë¤òÄɲ䷤Ƥ¢¤ê¤Þ¤¹¤Î¤Ç¡¢
ÀèÄø¥¢¥¿¥Ã¥Á¤·¤¿HitPlaySound.cs¤ÏÉÔÍפǤ¹¡£Box¤è¤ê¥¢¥¿¥Ã¥Á¤ò²ò½ü¤·¤Æ¤ª¤¤Þ¤¹¡£
¡¡PrefabsÆâ¤ÎBox¤òÁªÂò¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Î¥¹¥¯¥ê¥×¥È¤òÁª¤ó¤ÇRemove Component¤ò¤·¤Æ¤¯¤À¤µ¤¤¡£
Destroyer ¥¹¥¯¥ê¥×¥È¤¬ÉÕ¤¤¤Æ¤¤¤ë¾¤ÎBox¤Ë¤Ä¤¤¤Æ¤â¡¢Æ±¤¸¤è¤¦¤Ë Remove Compnent ¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- Áí¹ç
¥³¥á¥ó¥È¤ò¤«¤¯