【发布时间】:2020-05-28 23:19:53
【问题描述】:
我有一个粒子系统与它所跟随的对象相连。发射器速度在这里设置在刚体上。我想要的是让粒子系统像它一样跟随对象,但是当检测到触摸输入时,粒子将跟随触摸输入,将发射器速度更改为变换。运行我附加的代码时,有两个编译器错误我尝试过但未能修复。希望有人能看一下。
- “粒子系统”不包含对 '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