Hi, Bit of a beginner at unity and at Javascript coding in general. I'm making a 2d platformer game where objects can be controlled using a tracked fiducial marker. My main issue is that I struggle to find out what things are called in Unity in order to reference them in the code (the Unity resources are helpful, but sometimes a bit hard going).
Anyway, I've got some code which finds the x and y co-ordinates of a cube (and the rotation too) being controlled by the tracked fiducial, and now i want to use it's x & y co-ordinates in a loop to check if a gameobject exists at the co-ordinates ((myPosition), (myPosition2), z) on a loop where z = 0-50. After that i can work on making that secondary gameobject movable.
Heres my current code:
-function Update() {
myPosition = transform.position.x;
myPosition2 = transform.position.y;
myRotation = transform.rotation.eulerAngles.z;
Debug.Log(myPosition);
Debug.Log(myPosition2);
Debug.Log(myRotation);
}
//function Update() {
//For (z=0; z<50, z++){
//if (gameObject)
The code at the bottom is some early attempts at it before i realised i had no idea how to check if something was at a co-ordinate. I'm assuming my idea that i could just check if gameobject = true at co-ordinates (myPosition, myPosition2, z) is probably wrong, as I think that would end up as a vector3 instead of a location co-ordinate?
So my issues are 1. How do I check if a gameobject exists at a location? 2. can i use variables in a co-ordinate for a location to check? 3.Is a For loop the best way to check the z distance at my x,y co-ordinates, or am i doing this all wrong? 4. Oh and lastly, as a bonus question, once i find an object, i need to stop the loop. how do i do that?
Sorry for lots of questions, hopefully i'll get the hang of this quickly and bother you guys less :D