Question by
Nomaddc · Jun 12, 2016 at 03:37 PM ·
controlsmouseclick
On click interactions control
Here is the code from my player controller:
void Update()
{
if (gm.paused) return;
Fire1 = CrossPlatformInputManager.GetButton("Fire1");
if (Fire1 && !isMoving && gm.playerTurn && !gm.isResting && !gm.isBlocking && gm.stamina > 0)
{
Interact();
}
if (inCollision) {
destinationPosition = transform.position;
inCollision = false;
}
MoveObject();
}
And Interact function:
void Interact()
{
Ray ray = Camera.main.ScreenPointToRay(CrossPlatformInputManager.mousePosition);
mouseInput = new Vector3 (ray.origin.x, ray.origin.y, transform.position.z);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if ((!hit)) {
//Debug.Log ("Hit nothing");
return;
}
switch (hit.transform.tag.ToString())
{
case "Boss":
if (!hit.collider.isTrigger && inHitbox && gm.bossHp > 0) {
Debug.Log ("Hit Boss! " + hit.transform.tag);
if (gm.actions < 2) {
gm.bossHp -= 20;
gm.stamina -= 100;
gm.actions++;
}
} else if (hit.collider.isTrigger) {
Debug.Log ("Hit Hitbox! " + hit.transform.tag);
if (gm.actions < 2) {
destinationPosition = mouseInput;
gm.actions++;
}
}
break;
case "Arena":
Debug.Log("Hit something: " + hit.transform.tag);
if (gm.actions < 2) {
destinationPosition = mouseInput;
gm.actions++;
}
break;
default:
Debug.Log ("Hit Unknown");
break;
}
}
What I want to do is that if I click boss it will perform damage action once (right now it just spams it with Update rate, so multiple times in a mouse click). Any workaround for this?
Comment
Answer by Nomaddc · Jun 18, 2016 at 12:19 AM
Thinking of making it trigger on mouse release, not sure how to do it.
Your answer
Follow this Question
Related Questions
Elegant Solution to the Problem of Dealing With Multiple Key/Mouse Presses at the Same Time 0 Answers
How to make Rotation of HingeJoint2D constant via mouse button C# 1 Answer
Fast Clicking problem 0 Answers
How to get gameobject of script with raycast? 0 Answers
UI Buttons only respond to my screen touch instead of my mouse click 1 Answer