Advertisement
Guest User

Untitled

a guest
May 26th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CanvasArt : MonoBehaviour
  6. {
  7. public GameObject BackBox;
  8. public GameObject ClimableBox;
  9. public GameObject RegularBox;
  10. private GameObject player;
  11. private bool isDrawing;
  12. private float WidthSF;
  13. private float HeightSF;
  14. private Vector2[,] grid;
  15.  
  16. // Pixel art program: https://answers.unity.com/questions/1810907/how-do-i-make-a-pixel-art-program.html
  17.  
  18. void Start()
  19. {
  20. player = GameObject.FindGameObjectWithTag("Player");
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update()
  25. {
  26. Draw();
  27. }
  28.  
  29. void Draw() {
  30. isDrawing = player.GetComponent<HubInteraction>().cameraDraw;
  31. if (isDrawing && Input.GetKeyDown(KeyCode.F)) {
  32. grid = new Vector2[192, 108];
  33. WidthSF = Screen.width / 192;
  34. HeightSF = Screen.height / 108;
  35. for (int i = 1; i <= 192; i++)
  36. {
  37. for (int j = 1; j <= 108; j++)
  38. {
  39. // Assign a position scaled to fit screen size
  40. grid[i - 1, j - 1] = new Vector2(i * WidthSF, j * HeightSF);
  41. }
  42. }
  43. }
  44. if (isDrawing) {
  45. if (Input.GetMouseButtonDown(0)) {
  46. Vector2 mousePos = Input.mousePosition;
  47. mousePos = new Vector2 (Mathf.RoundToInt(mousePos.x / WidthSF) * WidthSF, Mathf.RoundToInt(mousePos.y / HeightSF) * HeightSF);
  48. Vector2 Square = grid[(int)mousePos.x, (int)mousePos.y];
  49. Instantiate(BackBox, Square, Quaternion.identity);
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement