using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestJoystickMove : MonoBehaviour
{
[SerializeField] private VariableJoystick joystick;
[SerializeField] private Rigidbody rBody;
[SerializeField] private float speed = 3f;
[SerializeField] private Button btnAttack;
[SerializeField] private GameObject bulletGo;
[SerializeField] private Transform bulletTr;
private void Start()
{
this.btnAttack.onClick.AddListener(() => {
GameObject go = Instantiate(this.bulletGo);
go.transform.position = this.bulletTr.position;
go.transform.rotation = this.bulletTr.rotation;
});
}
private void FixedUpdate()
{
if(joystick.Horizontal != 0 || joystick.Vertical != 0)
{
this.transform.Translate(Vector3.forward * this.speed * Time.deltaTime);
this.transform.rotation = Quaternion.Euler(0f, Mathf.Atan2(joystick.Horizontal, joystick.Vertical) * Mathf.Rad2Deg, 0f);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestAttack : MonoBehaviour
{
[SerializeField] private float bulletSpeed = 3f;
// Update is called once per frame
void Update()
{
this.transform.Translate(Vector3.forward * this.bulletSpeed * Time.deltaTime);
}
}