-1

我试图让一个物体慢慢消失然后被摧毁。我一直在使用iTween.fadeTo函数来实现所需的行为。但是,在指定的时间完成fadeTo()功能之后,对象会被销毁而不会消失。我不知道我需要设置什么才能使对象在被破坏之前消失。(下面的代码固定为所需的行为)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


void horizontalMovement ()
{
    mousePosition = Input.mousePosition;
    RaycastHit hit; 
    Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    if (Physics.Raycast (ray, out hit)) {
        if (hit.collider != null) {
            GameObject[] tiles = GameObject.FindGameObjectsWithTag("Floor");
            int interations = 0;
            foreach (GameObject tile in tiles) {
                interations = interations + 1;
                float tilePosition = tile.transform.localPosition.x; 
                float hitPostion = hit.transform.gameObject.transform.localPosition.x;
                float minimunValue = tilePosition - hitPostion;

                if (minimunValue == 0) {

                    iTween.FadeTo(tile, iTween.Hash(
                        "alpha", 1f,
                        "amount", 0f,
                        "time", 1f,
                        "onCompleteTarget", gameObject,
                        "onComplete", "destroy",
                        "oncompleteparams", tile)
                    );
                }
            }

            Debug.Log ("clean objects horizontally");
        }
    }
    Debug.Log ("Horizontal Movement is working" + mousePosition);
}

public void destroy(GameObject anyObject){
    Destroy (anyObject);
    Debug.Log ("Item will be destroyed");
}
4

1 回答 1

-1

Destroy()您可以使用它代替方法,nameYourObject.SetActive(false); 它也会使您的对象消失。

于 2020-08-27T01:46:13.773 回答