Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float x = 0;
        float y = 0;

        if (Input.GetKey(KeyCode.W))
        {
            y += 1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            y -= 1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            x -= 1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            x += 1;
        }
        var newVelocity = new Vector2(x, y).normalized *speed;

        if (newVelocity.sqrMagnitude == 0 ^ velocity.sqrMagnitude > 0)
        {
            UpdateAnimation();
        }
        velocity = newVelocity;

        // Find out look direction
        if ((cameraInHand?.recordingstatus ?? Recorder.Recordingstatus.NO_RECORDING) == Recorder.Recordingstatus.NO_RECORDING)
        {
            var mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
            mousePos = transform.worldToLocalMatrix.MultiplyPoint(mousePos);
            if (mousePos.x > mousePos.y)
            {
                if (-mousePos.x > mousePos.y)
                {
                    LookDirection = 2;
                }
                else
                {
                    LookDirection = 1;
                }
            }
            else
            {
                if (-mousePos.x > mousePos.y)
                {
                    LookDirection = 3;
                }
                else
                {
                    LookDirection = 0;
                }
            }
        }

        // Handling Input to pick up Camera
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (cameraInHand)
            {
                if (!cameraInHand.gameObject.activeInHierarchy)
                {
                    // Try to pick up
                    List <Collider2D> colliders = new List <Collider2D>();
                    GetComponent <Collider2D>().OverlapCollider(new ContactFilter2D(), colliders);
                    var projector = colliders.Find(c => c.GetComponentInParent <Projector>() != null);
                    if (projector)
                    {
                        cameraInHand.SetLastRecording(projector.GetComponentInParent <Projector>().GetRecording());
                        Destroy(projector.transform.parent.gameObject);
                        cameraInHand.gameObject.SetActive(true);
                        cameraInHand.ShowLastRecordingStillframe();
                    }
                }
                else if (cameraInHand.GetComponent <Recorder>().GetLastRecording()?.Finished ?? true)
                {
                    if ((!floorTilemap?.GetTile(floorTilemap.WorldToCell(this.transform.position))?.name.Equals("gitter")) ?? true)
                    {
                        // Put it down and start
                        var p = Instantiate <Projector>(projectorPrefab, cameraInHand.transform.position, cameraInHand.transform.rotation);
                        p.StartProjection(cameraInHand.GetLastRecording());
                        cameraInHand.gameObject.SetActive(false);
                        cameraInHand.SetLastRecording(null);
                    }
                }
            }
        }

        // Handling Input to get back to Main Menu
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(mainMenu, LoadSceneMode.Single);
        }

        // Updating UI to inform about pickup
        LevelUIBehaviour behav = cameraInHand.levelUIManagerObj.GetComponent <LevelUIBehaviour>();

        behav.DisplayPickupInfo(true);
        List <Collider2D> colliders2 = new List <Collider2D>();

        GetComponent <Collider2D>().OverlapCollider(new ContactFilter2D(), colliders2);
        var projector2 = colliders2.Find(c => c.GetComponentInParent <Projector>() != null);

        if (projector2)
        {
            behav.DisplayPickupInfo(true);
        }
        else
        {
            behav.DisplayPickupInfo(false);
        }
    }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     levelUI = levelUIManagerObj.GetComponent <LevelUIBehaviour>();
     print("Recorder here. This is my UI: " + levelUI);
 }