Question by
$$anonymous$$ · Nov 11, 2017 at 03:18 PM ·
scripting problemmovementtransformhandpunch
Script to make hand move in a punching motion not working?
Hello, I've made a script to make my player's hand move in a punching motion and declare that it is punching when it does so, and the script seems to be running, but my hand object is not moving at all. Any help would be much appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandMoveScript : MonoBehaviour {
public GameObject Hand;
private Animator ComAnimator;
public string TargetAnimation;
public int ButtonNumber;
public AudioSource PunchSound;
private float PunchTimer;
public float Recharge;
private Vector3 Stationary;
private float Extend;
public int ExtendAmount;
private bool Punching;
private bool Extending;
private bool Retracting;
public Vector3 StationaryPosition;
void Start (){
PunchTimer = Recharge * 60;
}
void Update (){
if (Punching == false) {
gameObject.transform.position = StationaryPosition;
}
if (Input.GetMouseButtonDown (ButtonNumber) && PunchTimer >= Recharge * 60) {
Punching = true;
Extending = true;
PunchTimer = 0;
}
if (Extending == true) {
Extend += 0.05f;
Hand.transform.position = StationaryPosition + new Vector3 (0, Extend, 0);
}
if (Extend >= 1) {
Extending = false;
Retracting = true;
}
if (Retracting == true) {
Extend += -0.05f;
Hand.transform.position = StationaryPosition + new Vector3 (0, Extend, 0);
if (Extend <= 0){
Extend = 0;
Punching = false;
Retracting = false;
}
}
}
}
Comment