Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - ochoag

#1
Hola estoy intentando poder inclinar una nave con el joystick pero no he podido. ¿como podría hacerlo? si me pudieran ayudar porfavor se los agradecería mucho.Este es el codigo que me funciona sin el joystick:
     
using UnityEngine;
using System.Collections;
 
public class PlayerController2 : MonoBehaviour
{
    public float speed;
    public float tilt;
   
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
     
        Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
        GetComponent<Rigidbody>().velocity = movement * speed;
 
        GetComponent<Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    }
}
 
pero aqui muevo la nave con el joystick:
using UnityEngine;
using System.Collections;
using UnitySampleAssets.CrossPlatformInput;
public class MoverNave : MonoBehaviour
{
    float sense = 5;
    public float speed;
   
 
    // Use this for initialization
    void Start()
    {
     
    }
    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector3(0, CrossPlatformInputManager.GetAxis("Vertical")) * Time.deltaTime * speed);
        float y = CrossPlatformInputManager.GetAxis("Mouse Y") * sense;
        transform.Rotate(0, y, 0);
        transform.Translate(new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), 0) * Time.deltaTime * speed);
        float x = CrossPlatformInputManager.GetAxis("Mouse X") * sense;
        transform.Rotate(x, 0, 0);
   
 
    }
 
}
    }
 
}
 
#2
General (Antiguo) / Input Mobile Controller
Abril 19, 2016, 09:55:55 PM
[quote author=iRobb" data-ipsquote-contapp="forums" data-ipsquote-contenttype="forums" data-ipsquote-contentclass="forums_Topic" data-ipsquote-contentid="35641" data-ipsquote-contentcommentid="129630 date=1460578841]El problema es que los touches no los filtras. Pillas todos los que vengan independientemente de la zona de pantalla.En el touch tienes una propiedad "position" que te indica en píxeles desde donde se lanzó. Habría que filtrar pues, un Rect por ejemplo que sería la zona del joystick, y que todo lo que salga fuera si lo ejecutes como disparo y el resto no. [/quote]Como podría hacer eso exactamente, bueno que me expliques mas o menos la idea. Y es sobre el script o con el editor? Gracias
#3
General (Antiguo) / Input Mobile Controller
Abril 13, 2016, 08:17:22 PM
Tengo un pequeño problema cuando toco la pantalla y disparo, lo que pasa es que se activa el touch cuando muevo el joystick y dispara continuamente mientras lo muevo como podria hacerle para que no dispare con el joystick y si dispare cuando toco otra parte de la pantalla.Este metodo es el que utilizo para disparar:   Touch myTouch = Input.GetTouch(0);
    Touch[] myTouches = Input.touches;
    for (int i = 0; i < Input.touchCount; i++)
    {
        Instantiate(disparo, arma1.position, disparo.rotation);
        Instantiate(disparo2, arma2.position, disparo2.rotation);
        Instantiate(disparo3, arma3.position, disparo3.rotation);
        AudioSource audio = GetComponent<AudioSource>();
        audio.Play();    }Esto es lo que utilizo para mover la nave mediante un joystick:using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class MoverNave : MonoBehaviour {    float sense = 5;
    float vel = 15;
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        transform.Translate (new Vector3 (0, CrossPlatformInputManager.GetAxis ("Vertical")) * Time.deltaTime * vel);
        float y = CrossPlatformInputManager.GetAxis("Mouse X") * sense;
        transform.Rotate(0,y,0);        transform.Translate (new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"),0) * Time.deltaTime * vel);
        float x = CrossPlatformInputManager.GetAxis("Mouse X") * sense;
        transform.Rotate(x,0,0);
    }
}Qué podria hacer al respecto?Si me pudieran ayudar se los agradeceria mucho.
#4
perdon por las molestias pero la linea 131 es la de game.transform.GetComponent<scriptGameState>().AddScore(); Y ya la indique en el codigo para que no haya confusion si me podrian ayudar porque este metodo no me esta funcionando Lo hize con SendMessage y si funciono pero el problema es que solo me permite manejar un GameObject...que podría hacer? 
#5
Tengo en mi codigo script disparo.
 
if (other.gameObject.tag == "roca1")
{

Vector3 reset =new Vector3(Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f), Random.Range(30.0f, 70.0f));
other.transform.position = reset;

Instantiate(explosion, transform.position, transform.rotation);
Destroy(gameObject);


//Sumamos un punto al GameState
game.transform.GetComponent<scriptGameState>().AddScore(); //esta es la linea 131
game2.transform.GetComponent<GameStateSurvival>().AddScore();
game3.transform.GetComponent<GameStateSurvival1>().AddScore();
game4.transform.GetComponent<GameStateSurvival2>().AddScore();
game5.transform.GetComponent<GameStateSurvival3>().AddScore();
game6.transform.GetComponent<GameStateSurvival4>().AddScore();
game7.transform.GetComponent<GameStateSurvivalInfinito>().AddScore();
game8.transform.GetComponent<scriptGameState100>().AddScore();
game9.transform.GetComponent<scriptGameState200>().AddScore();
game10.transform.GetComponent<scriptGameState300>().AddScore();
game11.transform.GetComponent<scriptGameState400>().AddScore();
game12.transform.GetComponent<scriptGameState500>().AddScore();
game13.transform.GetComponent<scriptGameState600>().AddScore();
game14.transform.GetComponent<scriptGameState700>().AddScore();
game15.transform.GetComponent<scriptGameState800>().AddScore();
game16.transform.GetComponent<scriptGameState900>().AddScore();
game17.transform.GetComponent<scriptGameState1000>().AddScore();
game18.transform.GetComponent<scriptGameStateER1>().AddScore();
game19.transform.GetComponent<scriptGameStateER2>().AddScore();
}

pero cuando pongo play al momento de colisionar el disparo con la roca me manda esto:
NullReferenceException: Object reference not set to an instance of an object
scriptDisparo OnTriggerEnter (UnityEngine.Collider other) (at Assets/GAMENORMAL/scriptsGAMENORMAL/scriptDisparo.cs:131)


y esto en mi script GameState que hace referencia al error.
game.transform.GetComponent<scriptGameState>().AddScore(); Este es mi GameState script:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class scriptGameState : MonoBehaviour {



static int puntos = 0;
static int vida = 10;
static float timer = 60; //Tiempo de juego


void Start()
{
InvokeRepeating("Timer", 1.0f, 1.0f);
puntos = 0;
timer = 60;
vida = 10;
}

void Update()
{

if (vida <= 0)
{

}

if (timer <= 0 && puntos >= 50)
{



}
if (timer <= 0 && puntos < 50)
{



}
print("Puntuacion: " + puntos);
print("Vidas: " + vida);

}




//Establecemos el tiempo de juego y los restamos
public void Timer()
{
if (--timer == 0)
{
CancelInvoke();
}
}

public void SumaTimer()
{
timer += 10;
}

public void PasarPuntos()
{
PlayerPrefs.SetInt("Puntuacion", puntos);
}
public void AddScore()
{
puntos += 1;

}

public void AddScore2()
{
puntos += 2;

}

public void DestroyEnemy()
{
puntos += 5;
}
public void AddScore3()
{
puntos += 3;

}
//Sumamos Vidas
public void SumarVidas()
{
vida += 1;
}
//Restamos Vidas
public void RestarVidas()
{
vida -= 1;
}

void OnGUI()
{
GUI.Label(new Rect(35, 60, 100, 20), "Puntuacion: " + puntos);
GUI.Label(new Rect(175, 60, 100, 20), "Vidas: " + vida);
GUI.Label(new Rect(345, 60, 100, 20), "Tiempo: " + timer);

}


}


Quiero llamar al metodo AddScore cuando el disparo colisione las rocas...Como puedo solucionar el problema?
#6

He estado intentando llamar una función de mi GameState:
 esta función:
con estas variables:
 bool _isWon;
 bool _isLost;  void Update ()
        {
            if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
            {
                Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
                Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");                LevelManager.Instance.LevelFinished();
                GameOver.Instance.Show(_isWon);
            }
        }or  void Update ()
        {
            if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
            {
                Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
                Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");                LevelManager.Instance.LevelFinished();
                GameOver.Instance.Show(_isLost);
            }
        }Todo para llamar que el juego se ha perdido o ganado pero en mi funcion Javascript GameState yo solo lo que quiero es agregar esto: function Update ()
{
   
    if(vida <=0)
    {
    aqui con se ha perdido
    }    if(timer <=0 && puntos >= 50)
    {
        aqui cuando se ha ganado
  
    }
    if(timer <=0 && puntos <  50)
    {
   
  aqui cuando se ha perdido
    }
    print("Puntuacion: "+puntos);
    print ("Vidas: "+vida);
   
}Alguien me puede ayudar en esa parte???...He estado investigando pero no he encontrado una solución para mi problema.
#7
I have been trying to call a function of c# to my JavaScript GameState:this function:with this variables: bool _isWon;
 bool _isLost;  void Update ()
        {
            if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
            {
                Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
                Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");                LevelManager.Instance.LevelFinished();
                GameOver.Instance.Show(_isWon);
            }
        }or  void Update ()
        {
            if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
            {
                Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
                Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");                LevelManager.Instance.LevelFinished();
                GameOver.Instance.Show(_isLost);
            }
        }everything to call that Game is Over or Game is Won but in my GameState JavaScript I have the functionally of GAME the only that I want is call these function to my part: function Update ()
{
   
    if(vida <=0)
    {
     here when is Lost
    }    if(timer <=0 && puntos >= 50)
    {
        here when is Won
  
    }
    if(timer <=0 && puntos <  50)
    {
   
    here when is Lost
    }
    print("Puntuacion: "+puntos);
    print ("Vidas: "+vida);
   
}someone can help me in these part.??? I have been searching but not have found the solution for my problem....