【发布时间】:2017-08-06 13:05:50
【问题描述】:
我正在使用线条渲染器来创建水果忍者风格的滑动效果。但它不起作用。Line 应该跟随鼠标 pos 但它没有这样做 这是代码。请帮我解决这个问题。并且此脚本附加到 (0,0,1) 位置的游戏对象行(空)。
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是否可以被相机看到。
-
@Jeroen 我试过不行
-
衬里渲染器是否启用了使用世界空间,它是游戏对象的子对象吗?