2017-06-27 3 views
-1

「Time Bubbles」を置くことができるゲーム(2D)を開発したいと思います。Unity - 特定のエリアに入ったときにすべての要素が遅くなります

「タイムバブル」私は次のことを試してみましたため、スクリプトで

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

public class TimeBubble : MonoBehaviour { 
private void OnTriggerEnter2D(Collider2D other) 
{ 

    GameObject temp = GameObject.Find(other.name); 

    temp.GetComponent<Rigidbody>().velocity = Vector3.zero; 
    temp.GetComponent<Rigidbody>().angularVelocity = Vector3.right * 0; 

    } 

} 

WICHが機能していません。

誰かが気泡の中のすべてのEleentを遅くする方法を知っていますか?

+0

"動作しない" 問題声明ではありません。あなたは何が起こったのか、あなたが期待したことを述べる必要があります –

答えて

0

観測!あなたはcharachterコントローラのように、速度を変更する別のスクリプトを使用している場合は

  • は、あなたがあなたのCharachterコントローラにspeedReductionFactorを渡す必要があります、このスクリプトから速度を設定し、それを使用してそこに速度を更新することはできませんし、入力ロジック、私はあなたにそれを残します。

    using System.Collections; 
    using System.Collections.Generic; 
    using UnityEngine; 
    
    public class TimeBubble : MonoBehaviour { 
    
        [Range(0,1)] 
        public float speedReductionFactor = .5f; 
    
        List <GameObject> objectsInside; 
    
        Rigidbody2D rb; 
    
        void Start() 
        { 
         objectsInside = new List<GameObject>(); 
        } 
    
        void OnTriggerEnter2D(Collider2D other) { 
         rb = other.gameObject.GetComponent<Rigidbody2D>(); 
         if (rb == null) 
          return; 
         rb.velocity *= speedReductionFactor; 
         objectsInside.Add(other.gameObject); 
        } 
    
        void OnTriggerExit2D (Collider2D other){ 
         rb = other.gameObject.GetComponent<Rigidbody2D>(); 
         if (rb != null && objectsInside.Contains(other.gameObject)) { 
          rb.velocity *= (1/speedReductionFactor); 
          objectsInside.Remove(other.gameObject); 
         } 
        } 
    
    } 
    
関連する問題