how i can set attack back to false ?
hello guys i have a problem to set attack back to false in my melee combat rpg game that im trying to make i have 2 scripts attached to a player first is basic movement script and second script for attacking all i want is when the player start to do attack animations i want it to stop moving, and when it finish the attacking i want it to go back to move , all done but i dont know and i cant set attack back to false so the player can move my scripts: using UnityEngine; using System.Collections;
public class player_motion123 : MonoBehaviour {
public Animator anim;
//public Transform center_point;
public Quaternion newrotation;
public float smooth = 0.05f;
public float speed;
public CharacterController controller;
public static bool ismoving=false;
public static bool isRunning=false;
public Transform cam;
bool grounded;
// jump
private float verticalVelocity;
public float gravity;
public float JumpForce;
public bool jumping;
void Start()
{
}
void Update ()
{
float v = Input.GetAxis ("Vertical");
float h = Input.GetAxis ("Horizontal");
if (player_Sword_Attack.attacking == false)
{
Move (h, v);
Run (h, v);
jump ();
}
}
void Move(float h ,float v)
{
if (h != 0f || v != 0f)
{
rotate (v, h);
controller.SimpleMove (transform.forward * speed);
anim.SetFloat ("Speed", 0.5f);
ismoving = true;
} else {
anim.SetFloat ("Speed",0);
ismoving = false;
}
}
void Run(float h, float v)
{
if (ismoving && Input.GetKey (KeyCode.LeftShift)) {
rotate (v, h);
controller.SimpleMove (transform.forward * speed * 2);
anim.SetFloat ("Speed", 1);
isRunning = true;
}
else if (ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
anim.SetFloat ("Speed", 0.5f);
isRunning = false;
}
else if (!ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
anim.SetFloat ("Speed", 0);
isRunning = false;
}
}
void jump()
{
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown (KeyCode.Space))
{
anim.SetBool ("Jumping", true);
verticalVelocity = JumpForce;
jumping = true;
if (isRunning)
verticalVelocity = JumpForce * 5f;
jumping = true;
}
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
anim.SetBool ("Jumping",false);
jumping = false;
}
Vector3 moveVector = Vector3.zero;
moveVector.x = Input.GetAxis ("Horizontal");
moveVector.y = verticalVelocity;
moveVector.z = Input.GetAxis("Vertical");
controller.Move (moveVector*Time.deltaTime);
}
void rotate(float v,float h) {
if (v > 0)
{
if (h > 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+45,0);
}
else if (h < 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+305,0);
}
else
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y,0);
}
}
else if (v < 0)
{
if (h > 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+135,0);
}
else if (h < 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+225,0);
}
else {
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+180,0);
}
}
else
{
if (h > 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+90,0);
}
else if (h < 0)
{
newrotation = Quaternion.Euler(0,cam.eulerAngles.y+270,0);
}
else {
newrotation = transform.rotation;
}
}
newrotation.x = 0;
newrotation.z = 0;
//We only want player to rotate in y axis
transform.rotation = Quaternion.Slerp (transform.rotation,newrotation, smooth);
//Slerp from player's current rotation to the new intended rotaion smoothly
}
} attack scripusing UnityEngine; using System.Collections;
public class player_Sword_Attack : MonoBehaviour {
private float lastTapTime = 1;
float tapSpeed = .3f;
private int clickCount = 0;
Animator anim;
public static bool attacking=false;
player_sword ps;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
ps = GetComponent < player_sword> ();
}
// Update is called once per frame
void Update ()
{
/*if (Input.GetMouseButtonDown(0)&& WieldWeapon.equiped == true)
{
if ( anim.GetInteger("Attack")==0)
anim.SetInteger("Attack", Random.Range(1,4));
Invoke("stoppress", 0.02f);
}
*/
if (Input.GetMouseButtonDown (0) && ps.sword_is_equiped==true)
{
attacking = true;
lastTapTime = Time.time;
if ((Time.time - lastTapTime) < tapSpeed)
{
clickCount += 1;
if(clickCount >= 3)
{
attacking = true;
anim.SetTrigger("slash3");
attacking = true;
clickCount = 0;
}
}
}
if ((Time.time - lastTapTime) > tapSpeed) {
if (clickCount == 2) {
anim.SetTrigger("slash2");
clickCount = 0;
} else if (clickCount == 1) {
anim.SetTrigger("slash");
clickCount = 0;
}
clickCount = 0;
}
}
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag=="opposite")
{
Debug.Log("enemy hitted");
//GameObject.FindGameObjectWithTag("Enemy").GetComponent<enemyMove>().gethit(damage);
}
}
/*bool inRange()
{
if (Vector3.Distance (transform.position, enemy.transform.position) < inrange)
return true;
else
return false;
}
*/
} t;
Your answer
Follow this Question
Related Questions
How can I address the Animator of a prefab from a C# script? 3 Answers
C# to set trigger on animator components of all children 3 Answers
Animations Not Working when Pressing Certain Keys 1 Answer
Editing other object's animator parameter... NullReferenceException? (VR) 0 Answers
MobController 1 Answer