i have these ray cast 'checker' cubes, called CubeBouncerJH and CubeBouncerKU, that check if they are surrounded by other cubes tagged 'Rcube', i implemented this by the following code:-
if(Input.GetKey("k"))
{
var hitK: RaycastHit;
//check if we're colliding
if(Physics.Raycast(transform.position, transform.right, hitK, 1))
{
//...with an object
if(hitK.collider.gameObject.tag =="Rcube")
{
hitK.collider.gameObject.transform.position.y=15;
}
}
}
now, for testing purposes, i used that 'transform.position.y=15' line to just bump the cube getting hit by the ray up to a different height, to check that im being able to affect properties of the cubes surrounding the checker cubes.
this is code in the 'update' function of the 'checker' cubes' script (they sit back to back so i can check in all 4 directions, eventually I'll be putting up 36 small cubes at 10 degree intervals to create an unavoidable circle of raycasting checkers.
this code worked perfectly, now, to rotate the cubes, im using another script, attached to each and every one of the 'rotatable' cubes surrounding the 'checkers'
at this point, i'd like to point out that the purpose of this code is to eventually facilitate rotation of individual slices of a rubik's cube sort of structure, and these checker cubes are to be invisible 'Slice confirmers' that stick around on the inside of the cube
the script attached to the rotatable cubes is called 'rotationScriptKeyLess.js':-
var willRotateHorizontallyNow: boolean;
var willRotateVerticallyNow: boolean;
var RotAxis : Vector3;
var MyAngle = 0;
var to : Transform;
var rotspeed = 0;
var CenterOfRotation;
var anglecounter=0;
function Update ()
{
if ( Input.GetKey("a") && willRotateHorizontallyNow == true)
{
if(MyAngle ==0)
{
RotAxis = Vector3.up;
MyAngle=90;
CenterOfRotation = GameObject.Find ("CubeBouncerJH");
rotspeed = 5;
}
}
if ( Input.GetKey("d") && willRotateHorizontallyNow == true)
{
if(MyAngle ==0)
{
RotAxis = Vector3.up;
MyAngle=90;
CenterOfRotation = GameObject.Find ("CubeBouncerJH");
rotspeed = -5;
}
}
if(anglecounter<MyAngle)
{
transform.RotateAround (CenterOfRotation.transform.position, RotAxis ,rotspeed);
anglecounter=anglecounter+Mathf.Abs (rotspeed);
}
else
MyAngle=0;
if(MyAngle == 0)
anglecounter=0;
}
this code works too, if i choose the cubes individually, and 'check' their 'willRotateHorizontallyNow' checkboxes to manually set the variables for their instance of the script to '1' in the inspector.
what i need, is for the value of their instance to get changed by the raycaster i made, the last bit of code i tried for the same was:-
if(Physics.Raycast(transform.position, transform.right, hitK, 1))
{
//...with an object
if(hitK.collider.gameObject.tag =="Rcube")
{
hitK.collider.gameObject.rotationScriptKeyLess.willRotateHorizontallyNow=true;
}
}
and well, it didn't work...
i know that the raycast is correctly hitting the cube, i know that the cube will do exactly what i want it to do once it's boolean value is changed, i just don't know how to change that value as a result of the raycast.
now, hopefully this is all clear enough, i need a solution, or a suggestion, anything! to make this code better, and more importantly, work) any ideas?
thank you :)