kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 5:55:36 GMT
Hey guys,
I am just a beginner so this might sound like a stupid problem, but I need some help with stopping player input when a text box is in action.
Basically I have a text box object in my game with an enable function:
public void EnableTextBox () { textBox.SetActive (true); // just showing the text box on screen
if (stopPlayerMovement) // a bool { vThirdPersonInput.canMove = false; } } I have put the public bool called canMove in both the text box object and at the top of the vThirdPersonInput script.
In the vThirdPersonInput script I then put this code in the virtual update ().
if (!canMove) { return; }
However, this doesn't work because it says in the first script that UnityEngine.GameObject doesn't contain a definition for canMove or for things already coded like canInput. What am I doing wrong.
|
|
|
Post by Invector on Feb 23, 2017 12:40:03 GMT
Welcome to the vForum Try the bool lockMovement instead ;)
|
|
kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 17:45:37 GMT
First of all thanks for the reply.
However, my script still doesn't recognize that bool.
I think I know whats causing the problem though. To access the vThirdPersonInput script I put a public gameobject in my text box manager code and then I put my player object, which holds the vThirdPersonInput, inside the text box manager in the unity editor. Is that the wrong way to access the vThirdPersonInput script?
so in other words I put this at the top
public GameObject vThirdPersonInput;
|
|
|
Post by Invector on Feb 23, 2017 20:52:09 GMT
There is several ways to access the player variables, in your new script make sure to add this at the top: using Invector.CharacterController;
then create a variable: public vThirdPersonController cc;
and in your method you can control the using: cc.lockMovement = true/false or use other bool directly like your stopPlayerMovement
|
|
kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 21:44:03 GMT
Hey I really appreciate your help!
The only problem now is that the lockMovement bool is behaving weird. The lockCamera bool works perfectly but the lockMovement bool makes it so that no matter what I press (in WASD) the character only goes only moves forward.
|
|
|
Post by sickscore on Feb 23, 2017 21:48:05 GMT
Hey I really appreciate your help! The only problem now is that the lockMovement bool is behaving weird. The lockCamera bool works perfectly but the lockMovement bool makes it so that no matter what I press (in WASD) the character only goes only moves forward. It's actually a small bug, which gets fixed in the next update. Go into your vThirdPersonAnimator script and replace line 154 with this line: animator.SetFloat("InputVertical", !stopMove || !lockMovement ? speed : 0f, 0.25f, Time.deltaTime); Cheers, sickscore
|
|
kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 22:22:03 GMT
animator.SetFloat("InputVertical", !stopMove || !lockMovement ? speed : 0f, 0.25f, Time.deltaTime);
so I put this where you told me to but it still has the same problem.
|
|
|
Post by sickscore on Feb 23, 2017 22:49:07 GMT
animator.SetFloat("InputVertical", !stopMove || !lockMovement ? speed : 0f, 0.25f, Time.deltaTime); so I put this where you told me to but it still has the same problem. Ok, than I don't get it I guess. When does your character move forward? When you have set "lockMovement = true" and then pressing WASD? Maybe try setting the speed variable of your vThirdPersonController to 0 after you lock the movement?
|
|
kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 23:06:06 GMT
Huh, this is weird.
when lockMovement = true; it doesn't actually do anything.
when lockCamera = true it disables the camera but it is also responsible for the forward movement when I press WASD.
So really the lockCamera is causing the issue.
|
|
|
Post by sickscore on Feb 23, 2017 23:17:05 GMT
Huh, this is weird. when lockMovement = true; it doesn't actually do anything. when lockCamera = true it disables the camera but it is also responsible for the forward movement when I press WASD. So really the lockCamera is causing the issue. Try putting your locking logic into LateUpdate () instead of Update (). If this doesn't solve the problem, someone else will find the solution, to late for me here :D
|
|
kdb44
New vMember
Posts: 17
|
Post by kdb44 on Feb 23, 2017 23:17:30 GMT
alright man thanks
|
|
|
Post by sickscore on Feb 23, 2017 23:21:37 GMT
No problem! If you don't get any other feedback, I will take a look at the code tomorrow.
|
|
|
Post by makebusy on Feb 28, 2017 9:47:01 GMT
No problem! If you don't get any other feedback, I will take a look at the code tomorrow. Good morning Gentlemen, I have the same issue, lockMovement doesn't seem to respond with using Invector.CharacterController; and public vThirdPersonController cc; set. I added public vThirdPersonMotor cm; since this bool appears in Motor, and used the following to no effect: GetComponent<Invector.CharacterController.vThirdPersonMotor>().lockMovement = true; GetComponent<Invector.CharacterController.vThirdPersonController>().lockMovement = true; cm.lockMovement = true; cc.lockMovement = true; I get a 'NullReferenceException: Object reference not set to an instance of an object' error where I'm setting this in my script also. The only thing available to manually drop there in the Inspector is the character, but this doesn't make a difference. lockMovement is stuck inside the enum LocomotionType, so its somehow not normally accessible as a bool. vThirdPersonInput looks like it has more (protected) control over inputs that actually lock the movement. *shrug* I dunno, but I'd like to know how to do this.
|
|
|
Post by Invector on Mar 1, 2017 13:37:15 GMT
Sorry, the lockMovement is actually being used with the Animator at runtime so you need to use the canInput from the vThirdPersonInput (change the protected to public) and call like this:
using UnityEngine; using System.Collections; using Invector.CharacterController;
public class vLockPlayer : MonoBehaviour { public vThirdPersonInput cc;
private void OnTriggerEnter(Collider other) { if(other.gameObject.tag.Equals("Player")) { cc = other.gameObject.GetComponent<vThirdPersonInput>(); cc.canInput = false; } } }
|
|
|
Post by sickscore on Mar 1, 2017 14:30:13 GMT
No problem! If you don't get any other feedback, I will take a look at the code tomorrow. Well...I guess I missed it *shame-on-me* Invector just posted the solution ;-)
|
|