- Home /
Player hanging on objects.
Hi, I am trying to make player hang, then climb on object. That's what I have in hanging script (attached to an object):
void OnTriggerEnter2D(Collider2D other)
{
if(other.name == "PlayerHang")
{
if (playerPosition.position.x >= hangableObject.position.x)
if (thePlayer.facingRight == true)
thePlayer.Flip();
if (playerPosition.position.x <= hangableObject.position.x)
if (thePlayer.facingRight == false)
thePlayer.Flip();
thePlayer.onHang = true;
}
}
Everything works fine, except:
I have multiple hangable objects in scene, so everytime it compares player position to one of (actually) 3 objects with hangable tag, it means that only one object works per scene.
What I am searching for is the way how to make it work with every object with this script attached. Something like self in Lua.
For now, I've created multiple hangable scripts in my location folder, where I'm using global variables:
void OnTriggerEnter2D(Collider2D other)
{
if(other.name == "PlayerHang")
{
if (playerPosition.position.x >= hangableObject1.position.x)
if(thePlayer.facingRight == true)
thePlayer.Flip();
if (playerPosition.position.x <= hangableObject1.position.x)
if (thePlayer.facingRight == false)
thePlayer.Flip();
thePlayer.onHang = true;
}
But I would appreciate other solutions.
Your answer
Follow this Question
Related Questions
Player rapidly accelerating instead of stopping 1 Answer
Distribute terrain in zones 3 Answers
Trigger help! 0 Answers
Guides or Tutorials for a Very Basic Enemy AI? [Unity 5] 1 Answer