Hallo,
I made a script to disable the movements of the thirdpersoncontroler, this only works when the keyboardkeys are going to be pushed down but not when the keyboardkeys are pushed down.
Also when unpressing the key, the thirdpersoncontroler just keeps moving a bit.
Code when having a collision:
void OnTriggerEnter (Collider col)
{
if (col.tag == "SpiderwebTag")
{
spideractive = true;
Destroy (Spiderweb);
//code to disable the movements of the thirdpersoncontroler
TCP.gameObject.GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter> ().ChangeMovementState ();
}
}
void TimerInvoke()
{
if (spideractive == true)
{
if (totalSec [0] < sec2wait)
{
totalSec [0]++;
} else {
CancelInvoke ("TimerInvoke");
}
if (totalSec [0] == 1)
{
Spin682017cAnimation2.SetActive (true);
Zombi_running.SetActive (true);
EthanBody.SetActive (false);
}
if (totalSec [0] == 2)
{
}
if (totalSec [0] == 4)
{
//code to enable the movements of the thirdpersoncontroler
TCP.gameObject.GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter> ().ChangeMovementState ();
Spin682017cAnimation2.SetActive (false);
EthanBody.SetActive (true);
}
}
}
Code using changemovement() in gamobject TCP:
public void ChangeMovementState()
{
tcpBlockMovement = !tcpBlockMovement;
}
void UpdateAnimator(Vector3 move)
{
//if status extra ivm Collision Zombies//
if (!tcpBlockMovement)
{
// update the animator parameters
m_Animator.SetFloat ("Forward", m_ForwardAmount, 0.1f, Time.deltaTime);
m_Animator.SetFloat ("Turn", m_TurnAmount, 0.1f, Time.deltaTime);
m_Animator.SetBool ("Crouch", m_Crouching);
m_Animator.SetBool ("OnGround", m_IsGrounded);
}
void ApplyExtraTurnRotation()
{
// help the character turn faster (this is in addition to root rotation in the animation)
//if status extra ivm Collision Zombies//
if (!tcpBlockMovement)
{
float turnSpeed = Mathf.Lerp(m_StationaryTurnSpeed, m_MovingTurnSpeed, m_ForwardAmount);
transform.Rotate(0, m_TurnAmount * turnSpeed * Time.deltaTime, 0);
}
}
public void OnAnimatorMove()
{
// we implement this function to override the default root motion.
// this allows us to modify the positional speed before it's applied.
if (m_IsGrounded && Time.deltaTime > 0)
{
//if status extra ivm Collision Zombies//
if (!tcpBlockMovement)
{
Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime;
// we preserve the existing y part of the current velocity.
v.y = m_Rigidbody.velocity.y;
m_Rigidbody.velocity = v;
}
}
}
Also tried the code disable keycode.uparrow:
void DisableKey( KeyCode key )
{
if( totalSec[0] == 1)
{
Event.current.Use();
}
}
void OnGui()
{
DisableKey (KeyCode.UpArrow);
}
Can someone help me to find the wright solution to make this work.
Thanks.