- Home /
Question by
DragonTTK · Jun 12, 2017 at 09:03 AM ·
gameobjectvector3mouseclick
Distance interaction
Hi i am trying to figure out how i can setup ranging in my project so you can click on object then fire arrows at it from 15 distance, but not working and only lets me fire arrows when im directly in front of object how can i fix this??
if (Input.GetKeyDown(KeyCode.Mouse0))
{
//pMove.isEnabled = false;
dmgSplat.transform.position = new Vector3(AIController.transform.position.x, 12.2f, AIController.transform.position.z);
//dmgSplat.transform.LookAt(Camera.main.transform);
//dmgSplat.transform.Rotate(Vector3.up - new Vector3(0, 180, 0));
dmgtxt.text = "" + damage;
StartCoroutine(playerHit());
if (slot.slot.item.category.name == "Bow")
{
dist = Vector3.Distance(PlayerManager.instance.currentPlayer.transform.position, transform.position);
print("" + dist);
if (dist <= 30) {
Vector3 position = new Vector3(PlayerManager.instance.currentPlayer.transform.position.x, PlayerManager.instance.currentPlayer.transform.position.y + 1.7f, PlayerManager.instance.currentPlayer.transform.position.z);
Instantiate(Arrow, position, PlayerManager.instance.currentPlayer.transform.rotation);
Vector3.MoveTowards(Arrow.transform.position, transform.position, 30);
//arrowInstance.AddForce(PlayerManager.instance.currentPlayer.transform.forward * Time.deltaTime * 35000);
damage = Random.Range(0, 5);
AIController.health -= damage;
}
}
else
{
print("punching");
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612123914im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Clicking a button to make a gameobject visible and interactable? 0 Answers
mouse click obj to initiate action, then locking the obj so action cant be repeated 1 Answer
MouseClick and gameObject 1 Answer
what to put in vector3 when instantiating Gameobject at Gameobject? 2 Answers
Calculating Scrolling GameObject x position scrolling pass another GameObject x postion (2D Game) 1 Answer