this is my enemies ( 2d game) when he go left he must turn left and when it he go right it musr turn right.
only this simple i need to do :). today i evening i can send my code also. thank you for answer.
Ya, I don’t think localscale can be negative, either (I mean, I think you can set it to a negative value, but <= 0 would be invisible?)
Maybe he’s asking about rotation … to “flip” the character?
I’ve reread his question about 10 times. I think this is what he is after.
public GameObject enemy; //set this gameobject in the inspector
public float lessThenBefor = 5f; // change this number to desired distance
void Update()
{
distance =Vector3.Distance(transform.position,enemy.position);
if(distance < lessThenBefor)
{
enemy.localscale.x = 0;
}else
{
enemy.localscale.x = 1;
}
}
so he wants to have a scale of 0? You could be right. Honestly, I have no idea. @Biallt , could you use a few more words to describe what you’re hoping to achieve?
on 2d the my image is looking right side when localscale.x is 1f, so when i make it -1f not 0 this this will be opposite of this image and will be look left.
Like, if you were using , for instance: ‘A’ = left and ‘D’ = right, then when you click ‘A’ set the localScale to -1 and ‘D’ set it to 1.
If it’s something like tap/click to move towards, then Check if that position is less than or greater than your current position.x ?
I’m not sure how much/which parts you need help with (now)
For sure… whenever you set the new move towards, simply compare the destination’s position.x to your transform.position.x and if it’s less, then set the scale -1 , else 1
You could do it with targets < 7 also but in case you add more targets or anything else, that may not work the same way, so the position one is better/will always work, I think.
Wherever you set it up, try something like this…
// setting new checkpoint
if(checkpoints[target+1].position.x < transform.position.x) transform.localScale = new Vector3(-1f,1,1);
else transform.localScale = new Vector3(1,1,1);
// This is if the checkpoint array is a Transform []
// otherwise, checkpoints[target+1].transform.position (etc)
Hey there, I’m happy for you and glad things are working.
If there is an error in the console, can you explain one more time when/how this is happening?