Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        Random.InitState(GameStarter.seed);
        foreach (Transform t in transform)
        {
            if (t.name == "Background")
            {
                background = t;
            }
        }

        stars           = new GameObject[starCountTouchable];
        backgroundStars = new List <GameObject>();

        // First star in the centre of the universe
        GameObject star = Instantiate(starPrefab, new Vector3(), new Quaternion());

        stars[0] = star;

        for (int i = 1; i < starCountTouchable; i++)
        {
            SpawnStar(i);
        }
        for (int i = 0; i < starCountTouchable * backgroundStarMultiplier; i++)
        {
            SpawnBackgroundStar();
        }

        for (int i = 0; i < pathCount; i++)
        {
            Star start = stars[Random.Range(0, starCountTouchable - 1)].GetComponent <Star>();
            Star end   = stars[Random.Range(0, starCountTouchable - 1)].GetComponent <Star>();
            if (start == end)
            {
                continue;
            }
            SpawnPath(start, end);
        }

        lr = FindObjectOfType <LookAround>();
        if (!lr)
        {
            return;
        }
        lr.GoToStar(stars[0]);
        stars[0].GetComponent <Star>().SetAsStarter();
        si = FindObjectOfType <SystemInfo>();

        shipping = TradeItem.NONE;
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (!lr)
        {
            return;
        }
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 3000f))
        {
            Star star = hit.transform.GetComponent <Star>();
            if (star)
            {
                lr.Aim(star, shipping);
                if (Input.GetMouseButtonDown(0))
                {
                    if (shipping == TradeItem.NONE)
                    {
                        lr.GoToStar(star.gameObject);
                        FindObjectOfType <MiniInfo>().Hide();
                    }
                    else
                    {
                        // Let's ship!
                        tycoon.GainMoney(si.ShipTo(star));
                    }
                }
            }
        }

        currentTimeToProduce -= Time.deltaTime;
        while (currentTimeToProduce < 0f)
        {
            currentTimeToProduce += timeToProduce;
            foreach (GameObject s in stars)
            {
                s.GetComponent <Star>().AutoProduce();
            }
            si.UpdateOwned();
        }

        Star currentStar = lr.currentStar.GetComponent <Star>();

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (shipping == TradeItem.NONE)
            {
                lr.GoToStar(tycoon.NextStar(currentStar).gameObject);
            }
            else
            {
                if (lr.CurrentDest())
                {
                    Star nextDest = tycoon.NextStar(lr.CurrentDest());
                    if (nextDest == currentStar)
                    {
                        nextDest = tycoon.NextStar(nextDest);
                    }
                    lr.Aim(nextDest, shipping);
                }
                else
                {
                    lr.Aim(tycoon.NextStar(currentStar), shipping);
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (shipping == TradeItem.NONE)
            {
                lr.GoToStar(tycoon.PreviousStar(currentStar).gameObject);
            }
            else
            {
                if (lr.CurrentDest())
                {
                    Star prevDest = tycoon.PreviousStar(lr.CurrentDest());
                    if (prevDest == currentStar)
                    {
                        prevDest = tycoon.PreviousStar(prevDest);
                    }
                    lr.Aim(prevDest, shipping);
                }
                else
                {
                    lr.Aim(tycoon.PreviousStar(currentStar), shipping);
                }
            }
        }
        credits.text = tycoon.GetCredits().ToString();
    }