// Use this for initialization void Start () { Inventory = new List<Item>(); if (GodMode) { Weapon w = new Weapon(WeaponType.Rifle); Inventory.Add(w); } //set active (for now) activeItem = Inventory[0]; Facing = FacingDirection.Left; Animation = AnimateState.Down; PlayerCamera = Camera.main; TargetPosition = transform.position; PlayerConvText = GameObject.Find("PlayerConvText"); textures = new Texture[4]; textures[0] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_back.png", typeof(Texture)); textures[1] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_front.png", typeof(Texture)); textures[2] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_left.png", typeof(Texture)); textures[3] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_right.png", typeof(Texture)); GetComponent<Renderer>().material.mainTexture = textures[2]; }
public void Play() { state = AnimateState.Playing; if (audioClip) { GetComponent <AudioSource>().clip = audioClip; GetComponent <AudioSource>().Play(); } }
void Reset() { state = AnimateState.None; indexDirection = direction; timeElapsed = 0f; loops = 0; delayElapsed = 0f; delay = UnityEngine.Random.Range(delayMIN, delayMAX); setSpriteIndexOnPlay = false; }
void Animate() { if (transform.localScale.z >= 0.194f) //dit moet wel ff anders.. Animation = AnimateState.Down; else if (transform.localScale.z <= 0.161f) Animation = AnimateState.Up; if (Animation == AnimateState.Up) transform.localScale = Vector3.Lerp(this.transform.localScale, new Vector3(transform.localScale.x, transform.localScale.y, 0.195f), Time.deltaTime * AnimationTime); else transform.localScale = Vector3.Lerp(this.transform.localScale, new Vector3(transform.localScale.x, transform.localScale.y, 0.160f), Time.deltaTime * AnimationTime); }
protected void WaypointWalk() { if (waypoints.Count > currentWaypoint) { Vector3 targetPosition = waypoints[currentWaypoint].position; Vector3 velocity; //Vector3 moveDirection = transform.TransformDirection(Vector3.forward); Vector3 moveDirection = myTargetPoint.TransformDirection(Vector3.forward); //Vector3 delta = targetPosition - transform.position; Vector3 delta = targetPosition - myTargetPoint.position; velocity = moveDirection.normalized * movingSpeed; if (delta.magnitude > 1) { characterAnimationState = AnimateState.run; } else { if (currentWaypoint < (waypoints.Count - 1)) { currentWaypoint++; } else { currentWaypoint = 0; } //Wait a random time between 0 and patrolRandomDelay (in seconds) if (waitingMaxTime > 0) { StartCoroutine(Wait(Random.Range(0, waitingMaxTime))); } } if (isWaiting || isHit || isDead) { characterAnimationState = AnimateState.idle; velocity = Vector3.zero; } GetComponent <Rigidbody>().velocity = velocity; } else { ClearWaypoints(); } }
protected void Walk(Vector3 targetPosition) { Vector3 velocity; //Vector3 moveDirection = transform.TransformDirection(Vector3.forward); Vector3 moveDirection = myTargetPoint.TransformDirection(Vector3.forward); //Vector3 delta = targetPosition - transform.position; Vector3 delta = targetPosition - myTargetPoint.position; float magnitude = delta.magnitude; //if (delta.magnitude > minimalDistance) //if ((delta.magnitude > minimalDistance) && (!isShooting) && (!isHit) && (!isDead)) if ((magnitude > minimalDistance) && (!isShooting) && (!isHit) && (isAlive)) { velocity = moveDirection.normalized * movingSpeed; //animation.CrossFade("run"); characterAnimationState = AnimateState.run; } else { velocity = Vector3.zero; //animation.CrossFade("idle"); if ((!isShooting) && (!isHit) && (!isDead)) //if ((!isAttaking) && (!isHit) && (!isDead)) { characterAnimationState = AnimateState.idle; } } //test-b if ((magnitude > minimalDistance)) { isWalkingToLastPosition = true; } else { isWalkingToLastPosition = false; } // test-e GetComponent <Rigidbody>().velocity = velocity; }
public AnimateState GetState( AdminShell.Referable rf, bool createIfNeeded = false) { if (rf == null) { return(null); } if (_states.ContainsKey(rf)) { return(_states[rf]); } if (createIfNeeded) { var nas = new AnimateState(); _states.Add(rf, nas); return(nas); } return(null); }
public void setPlayState(AnimateState targetState) { if (targetState == currentAnimState) { return; } preAnimState = currentAnimState; currentAnimState = targetState; if (eventStateChanged != null) { eventStateChanged(this, EventArgs.Empty); } StopCoroutine("ticker"); if (isAnimPlaying) { //Debug.Log("Couroutine begin .. "); StartCoroutine("ticker"); } }
public void Pause() { state = AnimateState.Pausing; }
private void startZoom() { this.state = AnimateState.ZOOM; this.zoomTime = zoomDuration; this.zoomOriginSize = this.Canvas.Bound.Size; }
IEnumerator Shoot() { bool hasShooted = false; //2011-05-26 if (shootingPause > 0) { float pastTime; while (isAlive) { pastTime = 0; isShooting = false; //2011-05-26 hasShooted = false; //2011-05-26 //if (isfollowingTarget) if (isAttaking && !isHit == true) { Quaternion toTargetRotation; Vector3 relativePos; //relativePos = lastVisiblePosition - transform.position; ////relativePos = lastVisiblePosition - aiCollider.position; ////toTargetRotation = Quaternion.LookRotation(relativePos); ////toTargetRotation = Quaternion.LookRotation(relativePos); Vector3 lastVisiblePositionTemp = lastVisiblePosition; lastVisiblePositionTemp.y = myTargetPoint.position.y; relativePos = lastVisiblePositionTemp - myTargetPoint.position; toTargetRotation = Quaternion.LookRotation(relativePos); //Wert 20 kann auch durch eine Variable ersetzt werden //if (EqualRotations(toTargetRotation, transform.rotation, 10)) if (EqualRotations(toTargetRotation, myTargetPoint.rotation, targetingTolerance)) { //Debug.Log("shoot - isEqualRotations"); isShooting = true; if (crossFadeAnimations) { GetComponent<Animation>().CrossFade(fightAnimation); } else { //animation.Play(fightAnimation); GetComponent<Animation>().PlayQueued(fightAnimation, QueueMode.PlayNow); } characterAnimationState = AnimateState.idle; yield return new WaitForSeconds(fightEffectsDelay); if (projectile != null) { GameObject proj; //proj = (GameObject)Instantiate(projectile, spawnPoint.position, gameObject.transform.rotation); //proj = (GameObject)Instantiate(projectile, spawnPoint.position, myTargetPoint.transform.rotation); proj = (GameObject)Instantiate(projectile, spawnPoint.position, spawnPoint.transform.rotation); //Destroy(proj, projectileLifeTime); if (projectileForce > 0) { proj.GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * projectileForce); } } //Debug.Log("shoot"); if (playSound) { fightSound.Play(); } if (calculationDamage) { //damage by Calculation if (Random.Range(0, 100) <= hitChance) { target.SendMessage("ShotDamage", Random.Range(minDamage, maxDamage)); } } if (shootAnimationLength < fightEffectsDelay) { yield return new WaitForSeconds(shootAnimationLength - fightEffectsDelay); pastTime = shootAnimationLength; } if (shootAnimationLength > fightEffectsDelay) { yield return new WaitForSeconds(fightEffectsDelay); pastTime = fightEffectsDelay; //Debug.Log("'Projectile Delay' is shorter than the fight animation lenght"); } //2011-05-26 -B isShooting = false; if (shootingPause > pastTime) { yield return new WaitForSeconds(shootingPause - pastTime); //hasShooted = true;//2011-05-26 -2 } //2011-05-26 -E hasShooted = true;//2011-05-26 -2 } } //2011-05-26 -B //isShooting = false; //if (shootingPause > pastTime) //{ // yield return new WaitForSeconds(shootingPause - pastTime); // //} if (hasShooted == false) { yield return new WaitForSeconds(0.5f); } //2011-05-26 -E } } else { Debug.LogError("Shooting Pause have to be longer than 0 seconds."); } }
protected void WaypointWalk() { if (waypoints.Count > currentWaypoint) { Vector3 targetPosition = waypoints[currentWaypoint].position; Vector3 velocity; //Vector3 moveDirection = transform.TransformDirection(Vector3.forward); Vector3 moveDirection = myTargetPoint.TransformDirection(Vector3.forward); //Vector3 delta = targetPosition - transform.position; Vector3 delta = targetPosition - myTargetPoint.position; velocity = moveDirection.normalized * movingSpeed ; if (delta.magnitude > 1) { characterAnimationState = AnimateState.run; } else { if (currentWaypoint < (waypoints.Count - 1)) { currentWaypoint++; } else { currentWaypoint = 0; } //Wait a random time between 0 and patrolRandomDelay (in seconds) if (waitingMaxTime > 0) { StartCoroutine(Wait(Random.Range(0, waitingMaxTime))); } } if (isWaiting || isHit || isDead) { characterAnimationState = AnimateState.idle; velocity = Vector3.zero; } GetComponent<Rigidbody>().velocity = velocity; } else { ClearWaypoints(); } }
protected void Walk(Vector3 targetPosition) { Vector3 velocity; //Vector3 moveDirection = transform.TransformDirection(Vector3.forward); Vector3 moveDirection = myTargetPoint.TransformDirection(Vector3.forward); //Vector3 delta = targetPosition - transform.position; Vector3 delta = targetPosition - myTargetPoint.position; float magnitude = delta.magnitude; //if (delta.magnitude > minimalDistance) //if ((delta.magnitude > minimalDistance) && (!isShooting) && (!isHit) && (!isDead)) if ((magnitude > minimalDistance) && (!isShooting) && (!isHit) && (isAlive)) { velocity = moveDirection.normalized * movingSpeed ; //animation.CrossFade("run"); characterAnimationState = AnimateState.run; } else { velocity = Vector3.zero; //animation.CrossFade("idle"); if ((!isShooting) && (!isHit) && (!isDead)) //if ((!isAttaking) && (!isHit) && (!isDead)) { characterAnimationState = AnimateState.idle; } } //test-b if ((magnitude > minimalDistance)) { isWalkingToLastPosition = true; } else { isWalkingToLastPosition = false; } // test-e GetComponent<Rigidbody>().velocity = velocity; }
void StopMoving() { GetComponent<Rigidbody>().velocity = Vector3.zero; characterAnimationState = AnimateState.idle; }
void StopMoving() { rigidbody.velocity = Vector3.zero; characterAnimationState = AnimateState.idle; }
void StopMoving() { GetComponent <Rigidbody>().velocity = Vector3.zero; characterAnimationState = AnimateState.idle; }
void PlayAnimationFinished() { loops++; switch (type) { case AnimateType.PlayOnce: if (playOnceRepeated) { indexDirection = direction; timeElapsed = 0f; loops = 0; delayElapsed = 0f; delay = UnityEngine.Random.Range(delayMIN, delayMAX); setSpriteIndexOnPlay = true; _state = AnimateState.Playing; } else { state = AnimateState.Completed; } break; case AnimateType.PingPongOnce: if (loops >= 2) { if (playOnceRepeated) { indexDirection = direction; timeElapsed = 0f; loops = 0; delayElapsed = 0f; delay = UnityEngine.Random.Range(delayMIN, delayMAX); setSpriteIndexOnPlay = false; _state = AnimateState.Playing; } else { state = AnimateState.Completed; } } else { switch (indexDirection) { case AnimateDirection.Forward: indexDirection = AnimateDirection.Backward; index--; SetSprite(); break; case AnimateDirection.Backward: indexDirection = AnimateDirection.Forward; index++; SetSprite(); break; } } break; case AnimateType.Loop: switch (direction) { case AnimateDirection.Forward: index = 0; SetSprite(); break; case AnimateDirection.Backward: index = sprites.Length - 1; SetSprite(); break; } break; case AnimateType.PingPong: switch (indexDirection) { case AnimateDirection.Forward: indexDirection = AnimateDirection.Backward; index--; SetSprite(); break; case AnimateDirection.Backward: indexDirection = AnimateDirection.Forward; index++; SetSprite(); break; } break; } }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { if (this.state == AnimateState.ZOOM) { float zoomRate = zoomRatio * (float) gameTime.ElapsedGameTime.TotalSeconds; this.scaleCanvas(zoomRate); this.zoomTime -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.zoomTime < 0) { this.startMove(); } } else if (this.state == AnimateState.MOVE) { this.moveCanvas((float)gameTime.ElapsedGameTime.TotalSeconds); this.moveTime -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.zoomTime > 0) { float zoomRate = zoomRatio * (float)gameTime.ElapsedGameTime.TotalSeconds; this.scaleCanvas(-zoomRate); this.zoomTime -= (float)gameTime.ElapsedGameTime.TotalSeconds; } if (this.zoomTime < 0) { this.Canvas.Bound.Size = destRect.Size; } if (this.moveTime < 0) { this.Canvas.Bound.Position = destRect.Position; this.state = AnimateState.NONE; if (this.OnCompleteAnimating != null) { this.OnCompleteAnimating(this); } } } base.Update(gameTime); }
private void startMove() { this.state = AnimateState.MOVE; this.zoomTime = zoomDuration; this.moveTime = moveDuration; this.moveOriginVelocity = destRect.Center - this.Canvas.Bound.Center; this.moveOriginVelocity /= this.moveDuration; }
IEnumerator Shoot() { bool hasShooted = false; //2011-05-26 if (shootingPause > 0) { float pastTime; while (isAlive) { pastTime = 0; isShooting = false; //2011-05-26 hasShooted = false; //2011-05-26 //if (isfollowingTarget) if (isAttaking && !isHit == true) { Quaternion toTargetRotation; Vector3 relativePos; //relativePos = lastVisiblePosition - transform.position; ////relativePos = lastVisiblePosition - aiCollider.position; ////toTargetRotation = Quaternion.LookRotation(relativePos); ////toTargetRotation = Quaternion.LookRotation(relativePos); Vector3 lastVisiblePositionTemp = lastVisiblePosition; lastVisiblePositionTemp.y = myTargetPoint.position.y; relativePos = lastVisiblePositionTemp - myTargetPoint.position; toTargetRotation = Quaternion.LookRotation(relativePos); //Wert 20 kann auch durch eine Variable ersetzt werden //if (EqualRotations(toTargetRotation, transform.rotation, 10)) if (EqualRotations(toTargetRotation, myTargetPoint.rotation, targetingTolerance)) { //Debug.Log("shoot - isEqualRotations"); isShooting = true; if (crossFadeAnimations) { GetComponent <Animation>().CrossFade(fightAnimation); } else { //animation.Play(fightAnimation); GetComponent <Animation>().PlayQueued(fightAnimation, QueueMode.PlayNow); } characterAnimationState = AnimateState.idle; yield return(new WaitForSeconds(fightEffectsDelay)); if (projectile != null) { GameObject proj; //proj = (GameObject)Instantiate(projectile, spawnPoint.position, gameObject.transform.rotation); //proj = (GameObject)Instantiate(projectile, spawnPoint.position, myTargetPoint.transform.rotation); proj = (GameObject)Instantiate(projectile, spawnPoint.position, spawnPoint.transform.rotation); //Destroy(proj, projectileLifeTime); if (projectileForce > 0) { proj.GetComponent <Rigidbody>().AddRelativeForce(Vector3.forward * projectileForce); } } //Debug.Log("shoot"); if (playSound) { fightSound.Play(); } if (calculationDamage) { //damage by Calculation if (Random.Range(0, 100) <= hitChance) { target.SendMessage("ShotDamage", Random.Range(minDamage, maxDamage)); } } if (shootAnimationLength < fightEffectsDelay) { yield return(new WaitForSeconds(shootAnimationLength - fightEffectsDelay)); pastTime = shootAnimationLength; } if (shootAnimationLength > fightEffectsDelay) { yield return(new WaitForSeconds(fightEffectsDelay)); pastTime = fightEffectsDelay; //Debug.Log("'Projectile Delay' is shorter than the fight animation lenght"); } //2011-05-26 -B isShooting = false; if (shootingPause > pastTime) { yield return(new WaitForSeconds(shootingPause - pastTime)); //hasShooted = true;//2011-05-26 -2 } //2011-05-26 -E hasShooted = true;//2011-05-26 -2 } } //2011-05-26 -B //isShooting = false; //if (shootingPause > pastTime) //{ // yield return new WaitForSeconds(shootingPause - pastTime); // //} if (hasShooted == false) { yield return(new WaitForSeconds(0.5f)); } //2011-05-26 -E } } else { Debug.LogError("Shooting Pause have to be longer than 0 seconds."); } }