プレーヤーの操作方法の変更
プレーヤーの動きの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 0.2f;
private Vector3 pos;
// ★★修正
void Update()
{
// PCでも動きを確認できるようにします(テクニック)
if (Application.isEditor)
{
float moveH = -Input.GetAxis("Horizontal") * moveSpeed;
float moveV = -Input.GetAxis("Vertical") * moveSpeed;
transform.Translate(moveH, 0, moveV);
Clamp();
}
else
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
float MoveH = -touch.deltaPosition.x * Time.deltaTime * moveSpeed;
float MoveV = -touch.deltaPosition.y * Time.deltaTime * moveSpeed;
transform.Translate(MoveH, 0, MoveV);
Clamp();
}
}
}
void Clamp()
{
pos = transform.position;
pos.x = Mathf.Clamp(pos.x, -6.5f, 6.5f);
pos.z = Mathf.Clamp(pos.z, -8.5f, 8.5f);
transform.position = pos;
}
}
プレーヤーの動きの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 0.2f;
private Vector3 pos;
// ★★修正
void Update()
{
// PCでも動きを確認できるようにします(テクニック)
if (Application.isEditor)
{
float moveH = -Input.GetAxis("Horizontal") * moveSpeed;
float moveV = -Input.GetAxis("Vertical") * moveSpeed;
transform.Translate(moveH, 0, moveV);
Clamp();
}
else
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
float MoveH = -touch.deltaPosition.x * Time.deltaTime * moveSpeed;
float MoveV = -touch.deltaPosition.y * Time.deltaTime * moveSpeed;
transform.Translate(MoveH, 0, MoveV);
Clamp();
}
}
}
void Clamp()
{
pos = transform.position;
pos.x = Mathf.Clamp(pos.x, -6.5f, 6.5f);
pos.z = Mathf.Clamp(pos.z, -8.5f, 8.5f);
transform.position = pos;
}
}
プレーヤーの操作方法の変更