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 - SaraW

#1
General (Antiguo) / Exagerar movimiento HTC
Junio 19, 2017, 10:58:04 AM
¡Buenos días  foreros! Espero que muchos de vosotros también estéis trabajando con las HTC...
 
Mi duda es: ¿La Script "SteamVR_TrackedObject" (la adjunto) controla el movimiento/posicionamiento del casco?. Mi idea es "exagerar" ese movimiento para que cuando el jugador en la vida real haga un paso, en Unity haga como 5 (para entendernos). El problema es que voy cortita de conocimiento de Scripts. ¿Alguien ya ha hecho esto?
 
Saludos
 
 
 



   
       
   
   
      //======= Copyright (c) Valve Corporation, All rights reserved. ===============

      //

      // Purpose: For controlling in-game objects with tracked devices.

      //

      //=============================================================================
   
   
      using UnityEngine;

      using Valve.VR;
   
   
      public class SteamVR_TrackedObject : MonoBehaviour

      {

          public enum EIndex

          {

              None = -1,

              Hmd = (int)OpenVR.k_unTrackedDeviceIndex_Hmd,

              Device1,

              Device2,

              Device3,

              Device4,

              Device5,

              Device6,

              Device7,

              Device8,

              Device9,

              Device10,

              Device11,

              Device12,

              Device13,

              Device14,

              Device15

          }
   
   
          public EIndex index;

          public Transform origin; // if not set, relative to parent

          public bool isValid = false;
   
   
          private void OnNewPoses(TrackedDevicePose_t[] poses)

          {

              if (index == EIndex.None)

                  return;
   
   
              var i = (int)index;
   
   
              isValid = false;

              if (poses.Length <= i)

                  return;
   
   
              if (!poses.bDeviceIsConnected)

                  return;
   


   

              if (!poses
.bPoseIsValid)

                  return;
   


   

              isValid = true;
   


   

              var pose = new SteamVR_Utils.RigidTransform(poses
.mDeviceToAbsoluteTracking);
   


   

              if (origin != null)


              {


                  transform.position = origin.transform.TransformPoint(pose.pos);


                  transform.rotation = origin.rotation * pose.rot;


              }


              else


              {


                  transform.localPosition = pose.pos;


                  transform.localRotation = pose.rot;


              }


          }
   


   

          SteamVR_Events.Action newPosesAction;
   


   

          void Awake()


          {


              newPosesAction = SteamVR_Events.NewPosesAction(OnNewPoses);


          }
   


   

          void OnEnable()


          {


              var render = SteamVR_Render.instance;


              if (render == null)


              {


                  enabled = false;


                  return;


              }
   


   

              newPosesAction.enabled = true;


          }
   


   

          void OnDisable()


          {


              newPosesAction.enabled = false;


              isValid = false;


          }
   


   

          public void SetDeviceIndex(int index)


          {


              if (System.Enum.IsDefined(typeof(EIndex), index))


                  this.index = (EIndex)index;


          }


      }
   


   

   


   


       
   





[/quote]


 
#2
General (Antiguo) / Resetear la vida
Abril 18, 2017, 04:11:05 PM
@TheBullet ya está solucionado! No sabes como te agradezco tu ayuda, de verdad :D Dejo por aquí la Script completa por si ayuda a alguien:
 



   
      using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Puntos : MonoBehaviour
{
    public static Puntos estadoJuego;

    void Start()
    {
        GameObject.Find ("healthbar");
        DontDestroyOnLoad (gameObject);

    }

    void Awake()
    {
        string nombreEscena = SceneManager.GetActiveScene().name;

        if (nombreEscena == "Main")
        {
            //Si estamos en al escena principal destruimos el anterior estadoJuego y asignamos el nuevo.
            if(estadoJuego != null)
                Destroy(estadoJuego.gameObject);

            estadoJuego = this;
        }
        else if (nombreEscena != "Main")
        {
            //Si la escena no es la principal lo destruimos (por si estuviera este Script en la escena de Muerte)
            Destroy(this.gameObject);
        }
    }
}

   

[/quote]
 
 
#3
General (Antiguo) / Resetear la vida
Abril 18, 2017, 01:48:14 PM
¡Muchísimas gracias por tu respuesta @TheBullet! Lo he probado y funciona a excepción de que yo quiero que en la Scene2 aparezca el healthbar copia (el último), el motivo es que lo utilizo como si fuera una puntuación...
 
Sobre qué objetos tienen las Scripts:
 
- Healthbar --> Empty Healthbar (canvas + imagen + texto)
 
- Puntos --> Empty Healthbar (") //Ya que quiero que la healthar se mantenga en la Scene 2, por eso el DontDestroyOnLoad
 
- LoadOnClick --> Boton Scene 2
#4
General (Antiguo) / Resetear la vida
Abril 18, 2017, 09:00:02 AM
¡Buenas a tod@s!
 
Os escribo porque me encuentro con el siguiente problema:
 
En mi juego, tengo una script de vida (Script healthbar), esta tiene una imagen y un texto. Al sufrir daño la imagen cambia el "fillAmount" y el valor del texto desciende. Al morir el jugador, se carga otra Scene 2 mostrando la healtbbar anterior (DontDentroyOnLoad, Script "Puntos") . En esa segunda Scene hay un botón que te permite volver a la Scene 1 y aquí esta mi problema. He encontrado en la red cómo guardar el valor de la healthbar original y eliminar la copia pero en mi caso quiero eliminar la original y guardar la copia. ¿Alguien sabe cómo?
 
También he intentado, dejando el valor de la healthbar original, restaurarlo. Pero al hacerlo ya no puedo sufrir daño (Script LoadOnClick).
 
 
 



   
      using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class HealthBar : MonoBehaviour {
    public Transform character;
    public Transform HBImage;
    public Transform HBText;
    public float maxHealth;
    public float currentHealth;
    public float health;

    // Use this for initialization
    void Start () {
        HBImage = gameObject.transform.GetChild().GetChild();
        HBText = gameObject.GetComponentInChildren<Text>().transform;
        HBImage.GetComponent<Image>().fillAmount = 1;
        currentHealth = maxHealth;
    }
    
    public void Damage(float damageAmount)
    {
        health = (currentHealth - damageAmount) / maxHealth;
        currentHealth -= damageAmount;
        currentHealth = Mathf.Round(currentHealth);
        HBImage.GetComponent<Image>().fillAmount = health;
        HBText.GetComponent<Text>().text = currentHealth.ToString();
        if (health <= )
        {
            SceneManager.LoadScene("MenuMuerte");
        }
    }
    void Update(){
    }


 }

   

[/quote]



   
      using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Puntos : MonoBehaviour {
    
    public static Puntos estadoJuego;
    public GameObject primerapuntuacion;


    void Awake (){
            
        if (estadoJuego==null){
            estadoJuego = this;
            DontDestroyOnLoad (gameObject);

        }

        else if (estadoJuego!=this){
            Destroy (gameObject);
        }
    }
}

   

[/quote]



   
      using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class LoadOnClick : MonoBehaviour {
    
    private float health;

    private float maxHealth;
    private float currentHealth;
    public Transform HBImage;
    public float DanoRestaurado = ;
    public GameObject healthBar;

    void Awake(){
        
        healthBar = GameObject.Find ("healthBar");
    }


    public void OnMouseDown(){
        
        healthBar.GetComponent<HealthBar> ().currentHealth = 10;
        healthBar.GetComponent<HealthBar> ().maxHealth = 10;
        healthBar.GetComponent<HealthBar>().Damage (DanoRestaurado);
        SceneManager.LoadScene("Main");

        }

    void Update(){
    }
}


       
   

[/quote]
 


  Muchísimas gracias :)
 
 
 
 
 
 
#5
General (Antiguo) / Nueva en el foro
Abril 17, 2017, 08:21:31 PM
Buenas a tod@s
 
Aquí otra noob con ganas de aprender y enseñar si se puede :)