Player is now able to pick up and drop the rag and the spray bottle

This commit is contained in:
Gregory Campbell
2020-06-01 20:10:18 -04:00
parent 104e6a0cb1
commit a14c816430
4 changed files with 253 additions and 6 deletions
+56
View File
@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameScript : MonoBehaviour
{
public GameObject Object;
private bool clicked = false;
private GameObject pickedUpItem;
// Start is called before the first frame update
void Start()
{
clicked = false;
}
// Update is called once per frame
void Update()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null)
{
if (hit.collider.gameObject.tag == "Item" && !clicked)
{
pickedUpItem = hit.collider.gameObject;
clicked = true;
Cursor.visible = false;
} else if (hit.collider.gameObject.tag == "Item" && clicked)
{
clicked = false;
Cursor.visible = true;
}
Debug.Log("Clicked " + pickedUpItem.name);
}
}
if(clicked)
{
pickedUpItem.transform.position = mousePos2D;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54fe94d557fed4245bd0ad22efbca7b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: