コード例 #1
0
ファイル: Runner.cs プロジェクト: PavelMasuk/Android
        void Start()
        {
            float offset = (coinsEndPoint.transform.position.x - coinsStartPoint.transform.position.x) / (coinsNumber - 1);

            int badCoinIndex = Random.Range(0, coinsNumber);

            for (int i = 0; i < coinsNumber; ++i)
            {
                Coin    coin          = Instantiate(coinPrefab);
                Vector3 tablePosition = coinsStartPoint.transform.position;
                tablePosition.x += offset * i;
                coin.GetComponent <CoinController>().TablePosition = tablePosition;
                coin.Tray = GetComponent <CoinTray>();
                coin.GetComponent <CoinController>().Index = i + 1;
                coin.GetComponentInChildren <Text>().text  = (i + 1).ToString();

                if (i == badCoinIndex)
                {
                    coin.Weight = 11;
                }
                else
                {
                    coin.Weight = 10;
                }
            }

            Debug.Log(badCoinIndex);
        }
コード例 #2
0
ファイル: CoinTray.cs プロジェクト: PavelMasuk/Android
        public bool Intersects(Coin coin)
        {
            if (name == "LeftPan" || name == "RightPan")
            {
                var spaceX     = GetComponent <BoxCollider2D>().bounds.center.x;
                var spaceY     = GetComponent <BoxCollider2D>().bounds.center.y;
                var coinX      = coin.GetComponent <Collider2D>().bounds.center.x;
                var coinY      = coin.GetComponent <Collider2D>().bounds.center.y;
                var halfWidth  = GetComponent <BoxCollider2D>().bounds.size.x / 2;
                var halfHeight = GetComponent <BoxCollider2D>().bounds.size.y / 2;
                if (Math.Abs(spaceX - coinX) <= halfWidth && Math.Abs(spaceY - coinY) <= halfHeight)
                {
                    return(true);
                }
            }
            if (GetComponent <SpriteRenderer>().bounds.Intersects(coin.GetComponent <Collider2D>().bounds))
            {
                return(true);
            }

            foreach (var trayCoin in coins)
            {
                if (trayCoin.GetComponent <Collider2D>().bounds.Intersects(coin.GetComponent <Collider2D>().bounds))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
 public bool Intersects(Coin coin)
 {
     return(GetComponent <Collider2D>().bounds.Intersects(coin.GetComponent <Collider2D>().bounds));
 }