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;

}

}

6626-cats00.jpg

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.