Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CanvasArt : MonoBehaviour
- {
- public GameObject BackBox;
- public GameObject ClimableBox;
- public GameObject RegularBox;
- private GameObject player;
- private bool isDrawing;
- private float WidthSF;
- private float HeightSF;
- private Vector2[,] grid;
- // Pixel art program: https://answers.unity.com/questions/1810907/how-do-i-make-a-pixel-art-program.html
- void Start()
- {
- player = GameObject.FindGameObjectWithTag("Player");
- }
- // Update is called once per frame
- void Update()
- {
- Draw();
- }
- void Draw() {
- isDrawing = player.GetComponent<HubInteraction>().cameraDraw;
- if (isDrawing && Input.GetKeyDown(KeyCode.F)) {
- grid = new Vector2[192, 108];
- WidthSF = Screen.width / 192;
- HeightSF = Screen.height / 108;
- for (int i = 1; i <= 192; i++)
- {
- for (int j = 1; j <= 108; j++)
- {
- // Assign a position scaled to fit screen size
- grid[i - 1, j - 1] = new Vector2(i * WidthSF, j * HeightSF);
- }
- }
- }
- if (isDrawing) {
- if (Input.GetMouseButtonDown(0)) {
- Vector2 mousePos = Input.mousePosition;
- mousePos = new Vector2 (Mathf.RoundToInt(mousePos.x / WidthSF) * WidthSF, Mathf.RoundToInt(mousePos.y / HeightSF) * HeightSF);
- Vector2 Square = grid[(int)mousePos.x, (int)mousePos.y];
- Instantiate(BackBox, Square, Quaternion.identity);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement