Skip to content
Permalink
94c7c7a256
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 73 lines (66 sloc) 1.7 KB
using UnityEngine;
using System.Collections;
public class MagicMarker : MonoBehaviour {
private GameObject Block;
// private float mouseX0;
// private float mouseY0;
// private float mouseX1;
// private float mouseY1;
private Vector3 mousePos1;
private Vector3 mousePos2;
private Vector3 blockRotation;
private Vector3 blockDrawPos;
private bool canDraw = true;
private Component inkUsed;
// Use this for initialization
void Start ()
{
Block = Resources.Load("Block") as GameObject;
inkUsed = GameObject.FindWithTag("MainCamera").GetComponent("InkLimit");
}
// Update is called once per frame
void Update ()
{
//if(canDraw == true)
//{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
StartCoroutine("DrawingBlocks");
}
if(Input.GetKeyUp (KeyCode.Mouse0))
{
StopCoroutine("DrawingBlocks");
}
//}
}
void DrawSwitchOff()
{
canDraw = false;
}
void DrawSwitchOn()
{
canDraw = true;
}
IEnumerator DrawingBlocks()
{
mousePos1 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
while(true)
{
yield return new WaitForSeconds(0.01f);
mousePos2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
blockDrawPos = new Vector3 ((mousePos1.x + mousePos2.x) / 2, (mousePos1.y + mousePos2.y) / 2, 0);
blockRotation = new Vector3(mousePos2.x - mousePos1.x, mousePos2.y - mousePos1.y, 0);
if(mousePos1 != mousePos2)
{
GameObject clone;
if(canDraw == true)
{
clone = Instantiate(Block, blockDrawPos, Quaternion.LookRotation(blockRotation)) as GameObject;
inkUsed.SendMessage("inkUsed",1);
clone.gameObject.transform.localScale += new Vector3 (0, 0, Vector3.Distance(mousePos1, mousePos2));
}
}
mousePos1 = mousePos2;
}
}
}