- Home /
This question was
closed Jan 25, 2015 at 03:35 PM by
Scribe for the following reason:
The question is answered, right answer was accepted
Question by
ce7ec · Jan 25, 2015 at 03:35 PM ·
pathfinding
Pathfinding work only in start()
Hello community, I made my Character moving by A* pathfinding and it is working.. But! Only if I do this:
void Start(){
seeker = GetComponent<Seeker>();
seeker.StartPath(transform.position, target.position, OnPathComplete);
characterController = GetComponent<CharacterController>();
}
But I want to move character only when I click right mouse button and it is not working when I do this.
// Update is called once per frame
void Update(){
if(Input.GetMouseButton(1)){
seeker = GetComponent<Seeker>();
seeker.StartPath(transform.position, target.position, OnPathComplete);
characterController = GetComponent<CharacterController>();
}
}
Any ideas how to make it works? I'm really sorry for my questions here, but I started with unity week ago and I never programmed in 3D.
Comment
Okay I fixed this issue.
You have to type it into FixedUpdate()
void LateUpdate(){
if(Input.Get$$anonymous$$ouseButtonDown(1)){
seeker = GetComponent<Seeker>();
seeker.StartPath(transform.position, CameraOperator.Right$$anonymous$$ouseClick, OnPathComplete);
characterController = GetComponent<CharacterController>();
}
}