我正在使用線渲染器來創建水果忍者風格刷卡效果。但它不工作。線應該按照鼠標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如果他們能夠被相機查看。 –