【问题标题】:Increases localscale depending on mouse position根据鼠标位置增加局部缩放
【发布时间】:2018-12-18 21:26:33
【问题描述】:

我正在尝试做一些不适合我的事情。我希望我的对象根据鼠标在 y 轴上的位置进行缩放。

void Update()
{
    var mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    mPosition.z = 0;
    target.transform.position = mPosition;
    float scaleValue = Mathf.Round(mPosition.y);
    target.transform.localScale = new Vector3(target.transform.localScale.x + scaleValue / 50f, target.transform.localScale.y + scaleValue / 50f, 0f);
    if (Input.GetMouseButtonDown(0) && canShoot)
    {
        Fire();
    }
}

问题是一旦游戏开始,物体(目标)就在稳步增长。我只是想做一些效果,当我将摩丝向上移动时,物体会缩小,当它向下移动时,物体会变大。我错了,谢谢!!!

【问题讨论】:

  • 你希望 y=0 的比例是多少?对于 y=10?对于 y=100? PartTimeIndie 写了一个可靠的答案,但你没有提供他们需要给你更具体的信息。

标签: c# unity3d


【解决方案1】:

问题是您要在每一帧上添加本地比例。你应该按照这些思路做一些事情:

Vector3 startScale;
void Awake(){
    startScale =   target.transform.localScale;
}
void Update()
{
    var mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    mPosition.z = 0;
    target.transform.position = mPosition;
    float scaleValue = Mathf.Round(mPosition.y);
    // you probably need to change the scaleValue to make it make more sense
    target.transform.localScale =startScale  * scaleValue;
    if (Input.GetMouseButtonDown(0) && canShoot)
    {
        Fire();
    }
}

【讨论】:

  • 是的,类似的,但它必须在代码上工作,因为如果 y == 0,比例为 0。我必须做类似的事情:如果 y == -5 然后目标。 localscale = 1f,如果 y == -4 那么 target.localscale = 0.9f....等等
  • 是的,我想,更重要的是为您指明正确的方向;)
猜你喜欢
  • 1970-01-01
  • 2016-09-12
  • 2020-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-26
  • 2015-04-20
  • 1970-01-01
相关资源
最近更新 更多