Unity粒子系统:使用脚本更改发射器速度

问题描述 投票:0回答:1

我有一个粒子系统与其后跟的对象相连。发射器速度在此处设置为刚体。我想要的是像这样使粒子系统跟随对象,但是当检测到触摸输入时,粒子将跟随触摸输入,将“发射器速度”更改为“变换”。在运行我附加的代码时,我尝试了两个且未能修复的编译器错误。希望有人来看看它。

  • “粒子系统”不包含'emitterVelocity',并且没有可访问的扩展方法'emitterVelocity'接受类型为'ParticleSystem'的第一个参数可以找到。第28行。
  • 'Transform'是一种类型,在给定的上下文中无效。第28行。
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;
        }
    }
}
c# unity3d compiler-errors particle-system
1个回答
0
投票

[首先,当尝试访问附加了Unity组件的Transform时,您想使用transform(注意小写的“ t”和大写的字母)。将Transform切换为transformthis.transform

transform是所有MonoBehaviours都具有的属性,它具有与调用this.GetComponent<Transform>()相同的值。相比之下,Transform是类型UnityEngine.Transform,也就是说,存在一个具有该名称的类。

第二,关于设置发射器,您可以在emitterVelocityMode中设置particle system's main component(标记为“发射器速度”)。 main的值为emitterVelocityMode

您可以说:

an enum named "ParticleSystemEmitterVelocityMode"
© www.soinside.com 2019 - 2024. All rights reserved.