Raycasts: Unterschied zwischen den Versionen

Aus hyperdramatik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 7: Zeile 7:
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UI;
public class Hit : MonoBehaviour
public class Hit : MonoBehaviour
{
{
Zeile 13: Zeile 12:
     int ledStatus = 0;
     int ledStatus = 0;
     int hitStatus = 0;  
     int hitStatus = 0;  
     // Start is called before the first frame update
     // Start is called before the first frame update
     // Update is called once per frame
     // Update is called once per frame
     void Update()
     void Update()
     { if (Input.touchCount >0)
     { if (Input.touchCount >0)
         { textDebug.text = "TOUCHED";
         {
           
           
 
             PerformRaycast();
             PerformRaycast();
         }
         }
Zeile 36: Zeile 29:
             PerformRaycast();
             PerformRaycast();
         }
         }
     }
     }
</code>
</code>

Version vom 7. April 2020, 08:27 Uhr

Raycasts dienen dafür, eine unsichtbare Achse von einem bestimmten Punkt in die Welt zu schlagen. In VR sind sie nützlich, um den Blicken der Benutzerin zu folgen. In AR können sie benutzt werden um eine Achse von der Kamera des Benutzer in die reale Welt zu projizieren, reale Projekte zu berühren und auf dem Tablet interagierbar zu machen. Der Code dafür ist folgender:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Hit : MonoBehaviour {

   public Text textDebug ;
   int ledStatus = 0;
   int hitStatus = 0; 
   // Start is called before the first frame update
   // Update is called once per frame
   void Update()
   { if (Input.touchCount >0)
       {
           PerformRaycast();
       }
       else
       {
           textDebug.text = "NO TOUCH";
           hitStatus = 0;
       }
       if (Input.touchCount >0 && Input.GetTouch(0).phase==TouchPhase.Began)
       {
           textDebug.text = "RAYCAST";
           PerformRaycast();
       }
   }