Example #1
0
    void CheckForBuilding()
    {
        RaycastHit hit;
        Ray        ray = new Ray(CheckPosition.position, Direction);

        if (Physics.Raycast(ray, out hit, 5f, BuildingMask))
        {
            canvasHit = hit.collider.GetComponent <PlayerCanvas>();

            canvasHit.AddToCanvas(hit.textureCoord, MyBrush);
            StartCoroutine(WaitForDestroy());
        }
    }
    void DrawOnCanvas()
    {
        RaycastHit hit;
        Ray        ray = new Ray(transform.position, Direction);

        if (Physics.Raycast(ray, out hit, 10f, CanvasMask))
        {
            textureCoord = hit.textureCoord;
            hitCanvas    = hit.collider.GetComponent <PlayerCanvas>();
        }

        if (hitCanvas != null)
        {
            hitCanvas.AddToCanvas(textureCoord, MyBrush);
        }
    }
Example #3
0
    private void Update()
    {
        if (GameManager.Gameplay.GameHasStarted)
        {
            if (prop.AllowControl)
            {
                if (prop.PlayerID == 1)
                {
                    ButtonPress("Jump_p1");
                }
                else if (prop.PlayerID == 2)
                {
                    ButtonPress("Jump_p2");
                }
            }

            if (!prop.AllowControl && !prop.AllowPainting)
            {
                isDrawing = false;
            }

            if (isDrawing)
            {
                if (prop.AllowPainting)
                {
                    Vector3 point = GetDrawPointVector();

                    if (activeIndicator == null)
                    {
                        activeIndicator = (GameObject)Instantiate(IndicatorPrefab, point, Quaternion.identity);
                    }

                    if (activeIndicator != null && drawPoints.Count > 0)
                    {
                        activeIndicator.transform.position = drawPoints[0];
                        activeIndicator.SetActive(true);
                    }

                    if (!myParticle.isPlaying)
                    {
                        myParticle.Play();
                        myParticle.transform.GetChild(0).gameObject.SetActive(true);
                    }

                    hitCanvas.AddToCanvas(textureCoord, MyBrush);

                    if (drawPoints.Count <= 0 || Vector3.Distance(point, drawPoints.Last()) > threshold)
                    {
                        drawPoints.Add(point);

                        GameManager.Player.PlayerLines[prop.PlayerID - 1].positionCount++;

                        if (prop.PlayerID == 1)
                        {
                            GameManager.Player.PlayerLines[prop.PlayerID - 1].SetPosition(lineIndex, new Vector3(-point.z, point.y, point.x - 0.01f));
                        }
                        if (prop.PlayerID == 2)
                        {
                            GameManager.Player.PlayerLines[prop.PlayerID - 1].SetPosition(lineIndex, new Vector3(point.z, point.y, -(point.x + 0.01f)));
                        }

                        lineIndex++;
                    }

                    // Only reduce when moving
                    if (prop.isMoving)
                    {
                        prop.ReducePaint(); // Reduce paint
                    }
                    else
                    {
                        prop.StopPaint();
                    }

                    //Play Spray Audio
                    GameManager.Player.PlayerAudio[prop.PlayerID - 1].PlaySpraySound();
                }
                else
                {
                    isDrawing = false;
                }
            }
            else
            {
                if (activeIndicator != null)
                {
                    activeIndicator.SetActive(false);
                }

                if (myParticle.isPlaying)
                {
                    myParticle.Stop();
                    myParticle.transform.GetChild(0).gameObject.SetActive(false);
                }

                // Reset Line
                GameManager.Player.PlayerLines[prop.PlayerID - 1].positionCount = 0;
                lineIndex = 0;

                // Stop reducing paint
                prop.StopPaint();

                //Stop spray audio
                GameManager.Player.PlayerAudio[prop.PlayerID - 1].StopSpraySound();

                Clear();
            }
        }
    }