- Home /
ERROR CS0199, ERROR CS1502, ERROR1503
Hello, I´m trying to make a menu for android and I´m trying to get a ray from a touch to tell me if the button is touched, but I get the ERROR CS0199 in the first line I´ll point out and the other another ERROR CS0199 in the second plus the other 2 errors. Since I´m translating from .js to .cs I guess I´ve ,missed something in the process. I´m not an expert in the programing field, so any help is very much apreciated. Thanks for the help in advanced.
This are the error codes I get:
Assets/Test/ScriptsTest/MenuControl.cs(15,51): error CS0119: Expression denotes a
method group', where a
variable',value' or
type' was expectedAssets/Test/ScriptsTest/MenuControl.cs(19,44): error CS0119: Expression denotes a
type', where a
variable',value' or
method group' was expectedAssets/Test/ScriptsTest/MenuControl.cs(19,36): error CS1502: The best overloaded method match for
UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, float)' has some invalid arguments 4. Assets/Test/ScriptsTest/MenuControl.cs(19,36): error CS1503: Argument
#1' cannot convertobject' expression to type
UnityEngine.Vector3'
And here is my code:
using UnityEngine; using System.Collections;
public class MenuControl : MonoBehaviour {
public GameObject videosButton;
public GameObject optionsButton;
public GameObject exitButton;
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.GetTouch.phase == TouchPhase.Began) { /*<== 1st Error */
RaycastHit hit;
if(Physics.Raycast(Ray, out hit, 100f)){ /* <== other 3 Errors */
GameObject buttonTouched = hit.transform.gameObject;
if(buttonTouched.tag == "Videos"){
}
if(buttonTouched.tag == "Options"){
}
if(buttonTouched.tag == "Exit"){
}
if(buttonTouched.tag != "Videos" && buttonTouched.tag != "Options" && buttonTouched.tag != "Exit"){
return;
}
}
}
}
}
Answer by Oribow · Apr 11, 2015 at 12:26 PM
You have make an instance of Ray. Ray is a class and classes must be instantiated before use.
Ray ray = new Ray (some Variables)
Thanks, altho I still get other errors, but I´ll try to sort them out with other entries
The last if in your code is unecesseary. GetTouch is a methode. $$anonymous$$ethodes are called with (some variables). Write GetTouch(0). The 0 tolds the methode which touch to give back. this should correct all errors. Sorry for the late answer.
thank yet again, much appreciated, altho I fixed it using this code and adding collider to the buttons:
using UnityEngine; using System.Collections;
public class $$anonymous$$enuControl : $$anonymous$$onoBehaviour {
float timerExit;
int counterExits;
public float maxTimeExit = 2.0f;
void Update () {
foreach( Touch touch in Input.touches ){
if( touch.phase == TouchPhase.Began ){
Ray ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0));
RaycastHit hit;
Physics.Raycast(ray, out hit, 100);
if (hit.collider != null){
if(hit.collider.gameObject.tag == "Videos"){
Application.LoadLevel("Videos");
Debug.Log("LoadVideos");
}
}
if(hit.collider.gameObject.tag != "Videos" && hit.collider.gameObject.tag != "Options" && hit.collider.gameObject.tag != "ExitYes"){
Debug.Log("NothingAtAll");
return;
}
}
}
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)){
counterExits = counterExits + 1;
if(counterExits <= 1){
Debug.Log ("Press again");
}
if(counterExits >= 2){
Debug.Log("ESCAPE!!!!");
Application.Quit();
}
}
if(timerExit >= maxTimeExit){
counterExits = 0;
}
timerExit = timerExit + Time.deltaTime;
if(counterExits == 0){
timerExit = 0.0f;
}
}
}