//playerに
using UnityEngine;
public class MovingObj : MonoBehaviour
{
//プレイヤーのスピード
public float joystickMoveSpeed = 5f;
//インスペクターから『Fixed Joystick』を追加。
public Joystick joystick;
//ジョイスティックの傾き度を取得
Vector3 joystickMoveVector;
private Animator anim;
private Rigidbody2D rb;
void Start()
{
anim = GetComponent();
// rigid = GetComponent();
rb = GameObject.Find("Player").GetComponent();
}
void Update()
{
if (!Input.GetMouseButton(0))
{
anim.SetBool("del", false);
return;
}
joystickMoveVector = Vector3.right * joystick.Horizontal + Vector3.up * joystick.Vertical;
if (joystickMoveVector != Vector3.zero) //ジョイスティックを動かす
{
transform.Translate(joystickMoveVector * joystickMoveSpeed * Time.deltaTime, Space.World);
anim.SetBool("del", true);
GetComponent().flipX = true;
}
Vector3 lookDir = new Vector3(joystick.Direction.x, 0, 0);
transform.right = -lookDir;
}
}
///////////////////////////
//playerに
using UnityEngine;
public class PlayerAttack : MonoBehaviour
{
public GameObject prefabBullet;
public GameObject prefabBullet2;
public Transform bulletPoint;
private bool ture;
public void Attack()
{
GetComponent().flipX = false;
Instantiate(prefabBullet2, bulletPoint.position, bulletPoint.rotation);
}
public void Attack2()
{
GetComponent().flipX = true;
Instantiate(prefabBullet, bulletPoint.position, bulletPoint.rotation);
}
}
///////////////////////////////
//bulletに
using UnityEngine;
public class Bullet : MonoBehaviour
{
void Update()
{
transform.position += new Vector3(-13f * Time.deltaTime, 0, 0);
}
}
_________________
public class Bullet2 : MonoBehaviour
{
void Update()
{
transform.position += new Vector3(13f * Time.deltaTime, 0, 0);
}
}
////////////////////
using UnityEngine;
public class Player : MonoBehaviour
{
public float joystickMoveSpeed = 5f;
public Joystick joystick;
Vector3 joystickMoveVector;
void Update()
{
if (!Input.GetMouseButton(0))
{
return;
}
joystickMoveVector = Vector3.zero;
joystickMoveVector.x = joystick.Horizontal;
joystickMoveVector.y = joystick.Vertical;
joystickMoveVector = Vector3.right * joystick.Horizontal + Vector3.up * joystick.Vertical * 1.7f;
if (joystickMoveVector != Vector3.zero)
{
transform.Translate(joystickMoveVector * joystickMoveSpeed * Time.deltaTime, Space.World);
}
else{
}
float angle = Mathf.Atan2(joystickMoveVector.y, joystickMoveVector.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, angle);
}
}