ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2020ǯ05·î21Æü(ÌÚ) 11:48:10ÍúÎò
¤½¤Î¤¿¤á¸½ºß¡¢Player¤Î°Üư®Å٤ϰìÄêÃͤǤ¹¡£
¤½¤³¤Çº£¸å¤Î¤¿¤á¤Ë¡¢¤Þ¤º¤Ï½¤¾þ»Ò¤Î¤Ä¤¤¤¿ÊÑ¿ô¤òÍÑ°Õ¤·¤Þ¤·¤ç¤¦¡£
¤³¤Á¤é¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤³¤È¤ÇPlayer¤Î°Üư®ÅÙ¤ò²ÄÊѤǤ¤ë¾õÂ֤ˤ¹¤ë¤³¤È¤¬ÌÜŪ¤Ç¤¹¡£
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { private float moveSpeed; // <= °Üư®ÅÙÍѤÎÊÑ¿ô¤òÄɲà // Start is called before the first frame update void Start() { moveSpeed = 0.05f; // <= °Üư®ÅÙÍѤˡ¢ÃͤòÂåÆþ Debug.Log(moveSpeed); // <= ÂåÆþ³ÎǧÍÑ } // Update is called once per frame void Update() { // º¸Ìð°õ¤¬²¡¤µ¤ì¤¿»þ if(Input.GetKey(KeyCode.LeftArrow)) { // º¸¤Ë¡Ö3¡×Æ°¤«¤¹ transform.Translate(-moveSpeed, 0, 0); // <= x ¤ÎÃͤò -0,05f ¤«¤é -moveSpeed¤ËÊѹ¹¤¹¤ë } // ±¦Ìð°õ¤¬²¡¤µ¤ì¤¿»þ if(Input.GetKey(KeyCode.RightArrow)) { // ±¦¤Ë¡Ö£³¡×Æ°¤«¤¹ transform.Translate(moveSpeed, 0, 0); // <= x ¤ÎÃͤò -0,05f ¤«¤é moveSpeed¤ËÊѹ¹¤¹¤ë } } }
¡¡¤³¤ÎÊѹ¹¤Ë¤è¤ê¡¢°ÜÆ°¤ËÍøÍѤ¹¤ë x ¤ÎÃͤò 0.05f ¤È¤¤¤¦¸ÇÄêÃͤ«¤é¡¢ÊÑ¿ô¤Ø¤ÈÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤·¤¿¡£
º£²ó¤Ï¸ÇÄêÃͤÈƱ¤¸ÃͤòmoveSpeed¤ËÂåÆþ¤·¤Æ¤¤¤Þ¤¹¡ÊDebug.Log¤Ç³Îǧ¤·¤Æ¤¤¤Þ¤¹¡Ë¡£
¡¡Æ±¤¸Æ°¤¤ò¤¹¤ë¤«¡¢³Îǧ¤ò¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
¡¡¤³¤ì¤Ë¤è¤ê¡¢Player¤Î°ÜÆ°¤Ë´Ø¤¹¤ë x ¤ÎÃͤϲÄÊѲ½¤¹¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤·¤¿¡£
Î㤨¤Ð¡¢moveSpeed = 0.1f¡¡¤Ë¤Ê¤ì¤Ð¡¢¸½ºß¤Î°Üư®ÅÙ¤Î2Çܤή¤µ¤Ç°ÜÆ°¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- Áí¹ç
¥³¥á¥ó¥È¤ò¤«¤¯