case3
This commit is contained in:
@@ -4,30 +4,19 @@ namespace StudyCase3
|
||||
{
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
public bool pick;
|
||||
Outline outline;
|
||||
bool pick;
|
||||
ThirdCharacterController player;
|
||||
private void Awake()
|
||||
{
|
||||
player = FindAnyObjectByType<ThirdCharacterController>();
|
||||
if (outline == null)
|
||||
outline = gameObject.AddComponent<Outline>();
|
||||
else
|
||||
outline = GetComponent<Outline>();
|
||||
outline.OutlineMode = Outline.Mode.OutlineVisible;
|
||||
outline.OutlineColor = new Color(0,1,1);
|
||||
outline.OutlineWidth = 10f;
|
||||
outline.enabled = false;
|
||||
gameObject.layer = LayerMask.NameToLayer("Item");
|
||||
}
|
||||
public void PickUp(Transform root)
|
||||
{
|
||||
pick = true;
|
||||
outline.OutlineWidth = 2f;
|
||||
gameObject.layer = LayerMask.NameToLayer("Default");
|
||||
transform.SetParent(root);
|
||||
}
|
||||
public void UnPickUp()
|
||||
{
|
||||
pick = false;
|
||||
outline.OutlineMode = Outline.Mode.OutlineVisible;
|
||||
outline.OutlineColor = new Color(0, 1, 1);
|
||||
outline.OutlineWidth = 10f;
|
||||
gameObject.layer = LayerMask.NameToLayer("Item");
|
||||
}
|
||||
@@ -41,5 +30,29 @@ namespace StudyCase3
|
||||
if (!pick)
|
||||
outline.enabled = false;
|
||||
}
|
||||
public void PickUp(Transform root)
|
||||
{
|
||||
if (pick) return;
|
||||
pick = true;
|
||||
transform.SetParent(root);
|
||||
outline.OutlineWidth = 2f;
|
||||
gameObject.layer = LayerMask.NameToLayer("Default");
|
||||
player.SetItems();
|
||||
}
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
if (player.pickMode == PickMode.Mouse)
|
||||
Select();
|
||||
}
|
||||
private void OnMouseExit()
|
||||
{
|
||||
if (player.pickMode == PickMode.Mouse)
|
||||
UnSelect();
|
||||
}
|
||||
private void OnMouseDown()
|
||||
{
|
||||
if (player.pickMode == PickMode.Mouse)
|
||||
PickUp(player.itemRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user