iTween.fadeTo()不会使对象褪色

时间:2017-01-21 01:04:06

标签: c# unity3d itween

我试图让一个物体慢慢消失然后被摧毁。我一直在使用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");
}

1 个答案:

答案 0 :(得分:-1)

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