Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (!isGameOver)
        {
            distance = (int)(ballRef.position.x * 0.5f);
        }

        fuelText.text  = "Paint Fuel: " + capacity.ToString();
        scoreText.text = distance.ToString() + " m";

        if (Input.GetMouseButton(0) && capacity > 0 && !isGameOver)
        {
            Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mouseWorldPos.z = 0f;

            if (Input.GetMouseButtonDown(0))
            {
                // make new path
                currPath = (LinePath)Instantiate(pathPrefab, Vector3.zero, Quaternion.identity);
                currPath.init(mouseWorldPos);

                paths.Add(currPath);
            }

            if (currPath != null)
            {
                // continue making path
                currPath.append(mouseWorldPos, this);
            }
        }

        foreach (LinePath path in paths)
        {
            path.makeLine();
        }

        Vector3 camPos = Camera.main.transform.position;

        camPos.z = 0f;
        float dist = Vector3.Distance(camPos, ballRef.position);

        if (dist > 2f)
        {
            Camera.main.transform.Translate((ballRef.position - camPos).normalized * (dist - 2f));
        }
    }