Okay so I am trying to develop a game where A player can choose a character and then said character can move like an RPG on another Scene. I am really struggling with making the Character move and would like help or Advice. The players are UI images set with a tag of Player. Players are in a Empty Game Object named PlayerCanvas under a GameObject child named players. Player trys to move but gets set back to previous position (doesn't move). The Player Creation script is on the child Players along with the Player Movement script.
Player Creation Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterCreation : MonoBehaviour {
private List<GameObject> players;
// Default Index for players
private int selectionIndex = 0;
private void Start()
{
players = new List<GameObject>();
foreach(Transform t in transform)
{
players.Add(t.gameObject);
t.gameObject.SetActive(false);
}
players[selectionIndex].SetActive(true);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
public void Select (int index)
{
if(index == selectionIndex)
{
return;
}
if(index < 0 || index >= players.Count)
{
return;
}
players[selectionIndex].SetActive(false);
selectionIndex = index;
players[selectionIndex].SetActive(true);
}
}
Player Movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < 0.5f) {
transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < 0.5f) {
transform.Translate(new Vector3(Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f, 0f));
}
}
}
If there is a way to make the Player move it would be helpful. Cheers.