- Home /
I need help ! = Tranform.position ?
I want the items moved to the second position x,y (red line)
but But only one is available.
Javascript Code:
function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="player")
{
transform.position.x = Random.Range (-30,33);
transform.position.y = -10.6062;
transform.position.x = Random.Range (-66,-52);
transform.position.y = -9.050232;
}
}
Try this one.I havent tried it function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="player")
{ if(transform.position.y==-9.050232) { transform.position.x = Random.Range (-30,33); transform.position.y = -10.6062; } else if(transform.position.y==-10.6062) { transform.position.x = Random.Range (-66,-52); transform.position.y = -9.050232;
}
}
Not sure what this is about.. but I know that checking for floating point equality like this is not a good idea. Also please format the code you paste here!
i try but no item no transform T.T
function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="player")
{ if(transform.position.y==-9.050232) { transform.position.x = Random.Range (-30,33); transform.position.y = -10.6062; } else if(transform.position.y==-10.6062) { transform.position.x = Random.Range (-66,-52); transform.position.y = -9.050232;
}
}
Answer by Bunny83 · Jan 12, 2013 at 12:44 PM
I'm not sure what exactly you want to do. I guess you want the item, when it is touched by the player and somewhere in the first area to move to the second atea and reverse.
Your code sets both position so only the last assignment will be used. You have to check where the item is at the moment of the collision.
Something like this:
// UnityScript
function OnCollisionEnter (collision:Collision)
{
if(collision.gameObject.tag =="player")
{
if (transform.position.y > -10)
{
transform.position.x = Random.Range (-30,33);
transform.position.y = -10.6062;
}
else
{
transform.position.x = Random.Range (-66,-52);
transform.position.y = -9.050232;
}
}
}
Since we don't know more about the mechanics in your game i can't give a more detailed / optimised answer.
There are two red lines in your picture, it is still unclear what you want, please explain with more words.
if player pick item , item random position As required.
Thank You all
oh come on... "as required"? What's the requirement?
Please use Google translate if you're having trouble finding the best English words.
Your answer
Follow this Question
Related Questions
How to reset a gameobject's transform? 2 Answers
Offset transform.parent.position - Help 1 Answer
measuring proximity with transform.distance 2 Answers