我正在使用线渲染器来创建水果忍者风格刷卡效果。但它不工作。线应该按照鼠标pos,但它不这样做这是代码。请帮我解决这个问题。这个脚本在(0,0,1)的位置附加到gameobject行(空)。线渲染器不按预期工作?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LineFOllow : MonoBehaviour {
int vertexcount =0;
bool mousedown = false;
private LineRenderer line;
void Start() {
line = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update() {
if (Input.GetMouseButtonDown(0)) // gets called when mouse is clicked
{
mousedown = true;
}
if (mousedown)
{
Debug.Log("called");
line.positionCount = vertexcount+1;
Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
line.SetPosition(vertexcount, mousepos);
vertexcount++;
}
if (Input.GetMouseButtonUp(0))// gets called when mouse is released
{
vertexcount = 0;
line.positionCount = 0;
mousedown = false;
}
}
}
什么是不工作;我们是在谈论一个错误,还是不是想要的效果? –
@Jereon想要的效果。我告诉它是去水果忍者 –
检查该行的点vector3.Z如果他们能够被相机查看。 –