I made a touch handler and there are quite a few errors. Im new to Unity and i have no idea what i did wrong so please explain. Also i never used c# before. I normally use c++ or c.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TouchInput:MonoBehaviour {
public LayerMask touchInputMask;
private List<GameObject> touchList = new List<GameObject>();
private GameObject[] touchesold;
private RaycastHit hit;
// Update is called once per frame
void Update () {
#if UNITY_EDITOR
if(Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0) ){
Ray ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray,out hit,TouchInputMask)) {
GameObject recipient = hit.transform.gameObject;
if(Input.GetMouseButtonDown(0)){
recipient.SendMessage("OnTouchDown",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(Input.GetMouseButtonUp(0)){
recipient.SendMessage("OnTouchEnded",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(Input.GetMouseButton(0)){
recipient.SendMessage("OnTouchStationary",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(Input.GetMouseButtonUp(0)){
recipient.SendMessage("OnTouchExit",hit.point,SendMessageOptions.DontRequireReceiver);
}
}
}
#endif
foreach (Touch touch in Input.touches) {
Ray ray = GetComponent<Camera>().ScreenPointToRay (touch.position);
if(Physics.Raycast(ray,out hit,TouchInputMask)){
GameObject recipient = hit.transform.gameObject;
if(touch.phase == TouchPhase.Began){
recipient.SendMessage("OnTouchDown",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Ended){
recipient.SendMessage("OnTouchEnded",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Stationary){
recipient.SendMessage("OnTouchStationary",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Canceled ){
recipient.SendMessage("OnTouchExit",hit.point,SendMessageOptions.DontRequireReceiver);
}
}
}
}
}
Errors:
Assets/Base Assets/C# Scripts/TouchInput.cs(17,48): error CS0103: The name `TouchInputMask’ does not exist in the current context
Assets/Base Assets/C# Scripts/TouchInput.cs(17,28): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit, float)’ has some invalid arguments
Assets/Base Assets/C# Scripts/TouchInput.cs(17,28): error CS1503: Argument #3' cannot convert
object’ expression to type `float’
Assets/Base Assets/C# Scripts/TouchInput.cs(44,56): error CS0103: The name `TouchInputMask’ does not exist in the current context
Assets/Base Assets/C# Scripts/TouchInput.cs(44,36): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit, float)’ has some invalid arguments
Assets/Base Assets/C# Scripts/TouchInput.cs(44,36): error CS1503: Argument #3' cannot convert
object’ expression to type `float’
.
What did i do wrong?