我有一个粒子系统与其后跟的对象相连。发射器速度在此处设置为刚体。我想要的是像这样使粒子系统跟随对象,但是当检测到触摸输入时,粒子将跟随触摸输入,将“发射器速度”更改为“变换”。在运行我附加的代码时,我尝试了两个且未能修复的编译器错误。希望有人来看看它。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragFingerMove : MonoBehaviour
{
private Vector3 touchPosition;
private ParticleSystem ps;
private Vector3 direction;
private float moveSpeed = 10f;
// Use this for initialization
private void Start()
{
ps = GetComponent<ParticleSystem>();
}
// Update is called once per frame
private void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
touchPosition.z = 0;
direction = (touchPosition - transform.position);
ps.emitterVelocity = Transform;
ps.velocity = new Vector2(direction.x, direction.y) * moveSpeed;
if (touch.phase == TouchPhase.Ended)
ps.velocity = Vector2.zero;
}
}
}
[首先,当尝试访问附加了Unity组件的Transform
时,您想使用transform
(注意小写的“ t”和大写的字母)。将Transform
切换为transform
或this.transform
。
transform
是所有MonoBehaviours
都具有的属性,它具有与调用this.GetComponent<Transform>()
相同的值。相比之下,Transform
是类型UnityEngine.Transform
,也就是说,存在一个具有该名称的类。
第二,关于设置发射器,您可以在emitterVelocityMode
中设置particle system's main
component(标记为“发射器速度”)。 main
的值为emitterVelocityMode
。
您可以说:
an enum named "ParticleSystemEmitterVelocityMode"