- Home /
Question by
sana_taj · Jul 09, 2021 at 03:07 PM ·
2d gametransform.positionraycasthit2d
I am making a Ball Sorting Puzzle Game, I am able to move a ball from flask1 to flask2 but unable to move ball back to flask 1 from flask 2. What could be the solution? I am Using C# for scripting
I am using mouse Button Down to for Ray
This the the script:
RaycastHit2D hit = Physics2D.Raycast(ray, Vector2.zero);
if (hit.collider.name == "flask1" && empty == false){
if (moved == false){
ball1.transform.position = flaskHead1.transform.position;
moved = true;
f1isEmpty = true;
f1hasElemet = 0;
}
}
if (hit.collider.name == "flask2" && f2isEmpty == true)
{
if (moved == true)
{
ball1.transform.position = flask2.transform.position;
moved = false;
f2isEmpty = false;
f2hasElemet = 1;
}
}
if (hit.collider.name == "flask1" && f1isEmpty == true)
{
if (moved == true)
{
ball1.transform.position = flask1.transform.position;
moved = false;
f1isEmpty = false;
f1hasElemet = 1;
}
if (hit.collider.name == "flask2" && f2isEmpty == false)
{
if (moved == false)
{
ball1.transform.position = flaskHead2.transform.position;
moved = true;
f2isEmpty = true;
f2hasElemet = 0;
} } Note: This is my first question on this forum, so I was unable to resolve the errors while adding script here . That is why it is so messed up.
Comment
Your answer
Follow this Question
Related Questions
How to make the camera acquire the position of a gameobject and start following it? 1 Answer
My raycasting script stops on error in play mode and i can't find out why 1 Answer
Is there a way of casting Rays at the end of the collider of an object ? 0 Answers
How can you move a camera a set amount of units based on the player's x position in a 2d game? 1 Answer