首页 > 解决方案 > Unity2D局部比例问题

问题描述

我有一个 2d 平台游戏,并且有这些带有巡逻系统的敌人:

public TextMeshProUGUI m_Object;
public SpriteRenderer sp;
public Transform groundCheck;

bool isFacingRight = true;

RaycastHit2D hit;


private void Update()
{
    hit = Physics2D.Raycast(groundCheck.position, -transform.up, 1f, groundLayers);

    
}

private void FixedUpdate()
{
    if(hit.collider != false)
    {
        if (isFacingRight)
        {
            rb.velocity = new Vector2(speed, rb.velocity.y);
            
        }
        else
        {

           
            rb.velocity = new Vector2(-speed, rb.velocity.y);
        }
    }
    else
    {
        isFacingRight = !isFacingRight;
        sp.transform.localScale = new Vector3(-transform.localScale.x, 1f, 1f);
        Debug.Log(transform.localScale.x);
        float placeholder = sp.transform.localScale.x;
        m_Object.transform.localScale = new Vector3(placeholder, 1f, 1f);
        Debug.Log(m_Object.transform.localScale.x);
    }
}

在最后部分,我试图翻转文本,使其保持面向逻辑的方式,但是它不起作用,因为当它碰到边缘时,文本消失了,当它到达另一个边缘时,文本又回来了。

任何想法,将不胜感激。

标签: c#unity3dgame-development

解决方案


推荐阅读