Jogo para Android
2 participantes
Página 1 de 1
Jogo para Android
Por favor, alguém me ajude a melhorar esse script que faz com que meu personagem pule, pois tenho que tocar um pouco forte no botão que faz com quer o personagem salte e isso só está acontecendo com o botão pular, o movimento para esquerda e direita estão funcionando perfeitamente.
using UnityEngine;
using System.Collections;
public class TouchPular : MonoBehaviour {
public Transform player;
public bool isGrounded;
public Transform ground;
private Animator animator;
public float forceFly = 190;
private Rigidbody2D rb;
private bool jumping;
private Gerenciador gerenciador;
private Animator playerAnimator;
public bool jumped;
//verifica o chao
public bool grounded;
public LayerMask whatIsGround;
//TESTE
public float jumpTime = 0.4f;
public float jumpDelay = 0.4f;
// Use this for initialization
void Start () {
gerenciador = FindObjectOfType (typeof(Gerenciador)) as Gerenciador;
animator = player.GetComponent<Animator> ();
rb = GetComponent<Rigidbody2D>(); //iniciando variavel, joga o componente rigidbody do personagem para rb
playerAnimator = GetComponent<Animator> ();
jumping = false;
gerenciador.StartGame ();
}
// Update is called once per frame
void Update () {
//isGrounded = Physics2D.Linecast (player.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Plataforma"));
foreach (UnityEngine.Touch touch in Input.touches)
{
if(this.GetComponent {
if(touch.phase != TouchPhase.Ended)
{
//if(this.name == "btnCima" && (isGrounded))
//{
// player.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, 1*forceFly));
//}
if(this.name == "btnCima" && isGrounded && !jumped)
{
player.GetComponent<Rigidbody2D>().AddForce(transform.up * forceFly);
jumpTime = jumpDelay;
jumped = true;
}
jumpTime -= Time.deltaTime;
if ((jumped)&&(jumpTime <= 0 )) {
animator.SetBool ("jumpPlayer",isGrounded);
jumped = false;
}
}
}
}
isGrounded = Physics2D.Linecast (player.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Plataforma"));
animator.SetBool ("jumpPlayer",!isGrounded);
//jumped = false;
}
void OnCollisionEnter2D(Collision2D colisor)
{
if (colisor.gameObject.name == "Porta")
{
if(gerenciador.IsColetado())
{
gerenciador.ProximoLevel(gerenciador.proximoLevel);
}else{
//indicando que nao coletou a quantidade necessaria
Debug.Log("Nao coletou a quantidade maxima");
}
}
}
}
using UnityEngine;
using System.Collections;
public class TouchPular : MonoBehaviour {
public Transform player;
public bool isGrounded;
public Transform ground;
private Animator animator;
public float forceFly = 190;
private Rigidbody2D rb;
private bool jumping;
private Gerenciador gerenciador;
private Animator playerAnimator;
public bool jumped;
//verifica o chao
public bool grounded;
public LayerMask whatIsGround;
//TESTE
public float jumpTime = 0.4f;
public float jumpDelay = 0.4f;
// Use this for initialization
void Start () {
gerenciador = FindObjectOfType (typeof(Gerenciador)) as Gerenciador;
animator = player.GetComponent<Animator> ();
rb = GetComponent<Rigidbody2D>(); //iniciando variavel, joga o componente rigidbody do personagem para rb
playerAnimator = GetComponent<Animator> ();
jumping = false;
gerenciador.StartGame ();
}
// Update is called once per frame
void Update () {
//isGrounded = Physics2D.Linecast (player.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Plataforma"));
foreach (UnityEngine.Touch touch in Input.touches)
{
if(this.GetComponent
if(touch.phase != TouchPhase.Ended)
{
//if(this.name == "btnCima" && (isGrounded))
//{
// player.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, 1*forceFly));
//}
if(this.name == "btnCima" && isGrounded && !jumped)
{
player.GetComponent<Rigidbody2D>().AddForce(transform.up * forceFly);
jumpTime = jumpDelay;
jumped = true;
}
jumpTime -= Time.deltaTime;
if ((jumped)&&(jumpTime <= 0 )) {
animator.SetBool ("jumpPlayer",isGrounded);
jumped = false;
}
}
}
}
isGrounded = Physics2D.Linecast (player.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Plataforma"));
animator.SetBool ("jumpPlayer",!isGrounded);
//jumped = false;
}
void OnCollisionEnter2D(Collision2D colisor)
{
if (colisor.gameObject.name == "Porta")
{
if(gerenciador.IsColetado())
{
gerenciador.ProximoLevel(gerenciador.proximoLevel);
}else{
//indicando que nao coletou a quantidade necessaria
Debug.Log("Nao coletou a quantidade maxima");
}
}
}
}
Giliarde- Iniciante
- PONTOS : 3023
REPUTAÇÃO : 1
Respeito as regras :
Re: Jogo para Android
Não tenho muito como ajudar pois está faltando o script "Gerenciador"
várias coisas neste script atual herdam parametros do outro script, então preciso dos 2
várias coisas neste script atual herdam parametros do outro script, então preciso dos 2
Re: Jogo para Android
Esta aqui o script do gerenciador. Por favor me ajude em como posso fazer para melhorar esse pulo, porque já faz muito tempo que estou enrolado nessa parte, procurei muito, mais não encontrei muito sobre a configuração para essas ações que serão realizadas no android.
public Vector2 posicaoInicialPlayer;
public Transform player;
public int proximoLevel;
public int quantidadeColetado = 0;
private int quantidadeMaxima = 5;
// Use this for initialization
void Awake () {
if (player != null)
{
posicaoInicialPlayer = player.position;
}
}
// Update is called once per frame
void Update () {
}
public bool IsColetado()
{
if (quantidadeColetado >= quantidadeMaxima) {
return true;
} else {
return false;
}
}
public void StartGame()
{
player.position = posicaoInicialPlayer;
}
public void GameOver(string nome)
{
Application.LoadLevel (nome);
}
public void AddQuantidade(int quantidade)
{
quantidadeColetado += quantidade;
}
public void ProximoLevel(int level)
{
Application.LoadLevel (level);
}
public Vector2 posicaoInicialPlayer;
public Transform player;
public int proximoLevel;
public int quantidadeColetado = 0;
private int quantidadeMaxima = 5;
// Use this for initialization
void Awake () {
if (player != null)
{
posicaoInicialPlayer = player.position;
}
}
// Update is called once per frame
void Update () {
}
public bool IsColetado()
{
if (quantidadeColetado >= quantidadeMaxima) {
return true;
} else {
return false;
}
}
public void StartGame()
{
player.position = posicaoInicialPlayer;
}
public void GameOver(string nome)
{
Application.LoadLevel (nome);
}
public void AddQuantidade(int quantidade)
{
quantidadeColetado += quantidade;
}
public void ProximoLevel(int level)
{
Application.LoadLevel (level);
}
Giliarde- Iniciante
- PONTOS : 3023
REPUTAÇÃO : 1
Respeito as regras :
Tópicos semelhantes
» [Ajuda] Dica de nome para meu jogo para Android :)
» como criar jogo fps para android ?
» Dúvida sobre jogo para android
» Jogo 2D para android
» Divulgação de jogo para Android
» como criar jogo fps para android ?
» Dúvida sobre jogo para android
» Jogo 2D para android
» Divulgação de jogo para Android
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos