我一直试图创建一种游戏机制,让您能够“吸吮”其他玩家的弹药,这是喷雾的形式,意在代表来自软管的水。
但是我无法从Unity的手动和脚本API获得任何东西,我编写的自定义脚本无法正常工作。
这是我的剧本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class suctionScript : MonoBehaviour {
public Collider suctionRadius;
public Transform suctionSphere;
public float suctionSpeed = 4;
public ParticleSystem blow;
// Use this for initialization
void Start () {
suctionRadius = GetComponent<SphereCollider>();
suctionRadius.enabled = !suctionRadius.enabled;
blow = GetComponent<ParticleSystem>();
}
void OnTriggerStay(Collider suctionedVictim)
{
if (suctionedVictim.gameObject.name == "suctionRadius")
{
transform.position = Vector3.MoveTowards(transform.position, suctionSphere.position, suctionSpeed);
}
}
void Suction()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
suctionRadius.enabled = !suctionRadius.enabled;
}
if (Input.GetKeyUp(KeyCode.Mouse1))
{
suctionRadius.enabled = !suctionRadius.enabled;
}
}
// Update is called once per frame
void Update () {
Suction();
}
}
目标是: 如果粒子系统发出的粒子发射在球体触发碰撞器内部,则内部发射将转换为其他地方的公共空物体。
这是怎么回事?