Question by
QuintanaDaniel · Apr 12, 2021 at 09:01 PM ·
2d gametouch
How can I move my player up and down in a Top-down shooter for mobile/android?
Hello everyone. I am working in a 2D project that will migrate to mobile devices once is done. My problem here is that my Player can not move when I input de direction on the joystick. I have tried with many tutorials and forums but I can not find the answer. I have tried many different scripts but with no solution. Here you can see the Game view of my project and the joystick that I am trying to use and the button that will allow the player to shoot, that I can not make work either. Can you point me in the right direction to implement an useful command to move my character and let my player shoot? Here are the codes that I am using: Many thanks in advance.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Joystick joystick;
float horizontalMove = 0f;
public float moveSpeed = 15f;
// Update is called once per frame
void Update()
{
if(joystick.Horizontal >= 0.2f)
{
horizontalMove = moveSpeed;
}else if (joystick.Horizontal <= -0.2f)
{
horizontalMove = -moveSpeed;
}else
{
horizontalMove = 0f;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FireButton : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
void Shoot()
{
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
}
}
image1.png
(35.8 kB)
Comment