EDIT :
I tired using the touch manager code thats now opensource, I’m having a very hard time with it …
Hi all, I need some basic touch code for C#
Here’s the JS version that I already have
function Update () {
//if ( Got == true ) {
//SeqPlay();
//}
//KeyD();
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
var ray = Camera.main.ScreenPointToRay (touch.position);
var hit:RaycastHit = new RaycastHit();
if (Physics.Raycast (ray,hit,1000)) {
if(hit.collider.gameObject == this.gameObject) {
// code to run
//AllofIt();
}
}
}
}
}
And here’s the C# code that i’ve attempted to write…
void Update () {
foreach (Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay (touch.position);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray,hit,1000)) {
if(hit.collider.gameObject == this.gameObject) {
// the code we need to run
// Add();
// AllofIt();
}
}
}
Ok, but how do I get the raycast working in C#, my new project is totally C#, and I really don’t want to use JS just for touch management
I only have about 3 objects that need this , but I’m going to look in the unity wiki for said touch manager code- fresh out of cash for asset store stuff
It looks quite nice so far, though it’s a bit confusing that he is using DPI, but doesn’t seem to have any code to retrieve the actual DPI (in the Manager class it’s hardcoded and in the options it switches between the set value and editor DPI). May be an issue, since on Android the DPI can vary anything from 100dpi to 300+ dpi and 326 dpi or so on iPhone’s Retina.
But other than that it seems well design. Should test it too later when I get more time. Thanks for the find