// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { roomba = animator.GetComponent <RoombaBehaviour> (); hd = animator.GetComponent <HurtAndDamage> (); hd.canHurtOther = true; // decide where to shoot the roomba at targetPos = roomba.targetLastPos; // guess where the player might be at after fade seconds // if(roomba.target){ // Rigidbody2D rb = roomba.target.GetComponent<Rigidbody2D> (); // if(rb){ // targetPos = shootPos + (Vector3)(rb.velocity * fadeSeconds); // } // } Vector3 targetDir = animator.transform.up; if (roomba.cs.controller == Controller.Boss) { targetDir = (targetPos - animator.transform.position).normalized; } else if (roomba.cs.controller == Controller.Hacker) { targetDir = roomba.incomingVelocity.normalized; Debug.Log(targetDir); } roomba.body.velocity = targetDir * roomba.thrust; animator.SetFloat("velocity", roomba.body.velocity.magnitude); // enable collision check for explosion roomba.checkCollision = true; // reset distToTarget animator.SetFloat("distToTarget", 200f); }
// Use this for initialization void Start() { ct = GetComponent <ChaseTarget> (); cs = GetComponent <ControlStatus> (); hd = GetComponent <HurtAndDamage> (); if (ct) { defaultRotSpeed = ct.rotationSpeed; defaultMoveSpeed = ct.moveSpeed; } virusState = VirusState.Idle; previousState = VirusState.Idle; ResetActions(); if (OnIdleStart != null) { OnIdleStart(this.transform); } paralyzeTime = 5f; tp = GetComponent <VirusTargetPicker> (); vpm = transform.parent.GetComponent <VirusPosManager> (); if (cs) { cs.OnCutByEnemy += StopStateControl; cs.OnCutByPlayer += StopStateControl; cs.OnLinkedByEnemy += StartStateControl; cs.OnLinkedByPlayer += StartStateControl; } }
public void EndImmune(bool setColor = true) { HurtAndDamage hd = GetComponent <HurtAndDamage> (); if (hd) { hd.canHurtSelf = true; } // if (setColor) { // if (GetComponent<SpriteRenderer> ().color == Color.green) { // GetComponent<SpriteRenderer> ().color = Color.white; // } // } isImmune = false; }
/* end the harmless period, this object would be hurt again*/ public void EndHarmless(bool setColor = true) { HurtAndDamage hd = GetComponent <HurtAndDamage> (); if (hd) { hd.canHurtOther = true; } // if (setColor) { // if (GetComponent<SpriteRenderer> ().color == Color.green) { // GetComponent<SpriteRenderer> ().color = Color.white; // } // } isHarmless = false; }
// add for charging dart // Use this for initialization void Start() { myRigidbody = GetComponent <Rigidbody2D>(); myCapsuleColl = GetComponent <CapsuleCollider2D> (); defaultColliderWidth = myCapsuleColl.size.x; newColliderWidth = defaultColliderWidth * colliderAmpFactor; energySys = GetComponent <PlayerEnergy> (); linecut = GetComponent <LineCut> (); healthSys = GetComponent <HealthSystem>(); hd = GetComponent <HurtAndDamage> (); movement = GetComponent <PlayerMovement> (); }
public void StartHarmless(bool setColor = true) { // during harmless, this obj cannot hurt others any more HurtAndDamage hd = GetComponent <HurtAndDamage> (); if (hd) { hd.canHurtOther = false; } // if (setColor) { // if (GetComponent<SpriteRenderer> ().color == Color.white) { // GetComponent<SpriteRenderer> ().color = Color.green; // } // } isHarmless = true; }
/* this object could only hurt other when: * 1. this.canHurtOther && other.canHurtSelf * 2. this.canHurtOther && other does not have HurtAndDamage */ bool VerifyHurtOther(Transform other) { if (!this.canHurtOther) { return(false); } HurtAndDamage hd = other.GetComponent <HurtAndDamage> (); if (hd == null || hd.canHurtSelf == true) { return(true); } else { return(false); } }
void ReleaseIdleVirus() { // release all idle virus // get all childs which is a virus foreach (Transform child in transform) { // does if have a objectIdentity and the identity is virus? ObjectIdentity oi = child.GetComponent <ObjectIdentity> (); if (oi && oi.objType == ObjectType.Virus) { // is the virus Idle? VirusStateControl sc = child.GetComponent <VirusStateControl> (); if (sc) { if (sc.virusState == VirusStateControl.VirusState.Idle) { // change the state to "chase" sc.OnChaseStart += SetReleaseParent; sc.OnChaseStart += DisableLineRenderer; sc.virusState = VirusStateControl.VirusState.Chase; // WTF? hack to stop virus from lingering on the wall HurtAndDamage hd = sc.GetComponent <HurtAndDamage> (); if (hd) { hd.instantKillSelf = true; } ChaseTarget ct = sc.GetComponent <ChaseTarget> (); ct.moveSpeed = ct.moveSpeed * moveSpeedFactor; sc.OnChaseStart -= SetReleaseParent; sc.OnChaseStart -= DisableLineRenderer; } } } } }
// Use this for initialization void Start() { body = GetComponent <Rigidbody2D> (); fov = GetComponent <FieldOfView> (); cs = GetComponent <ControlStatus> (); lu = GetComponent <LineUpdate> (); animator = GetComponent <Animator> (); hd = GetComponent <HurtAndDamage> (); // set default targets targets = playerTargets; // add actions cs.OnLinkedByEnemy += SetPlayerTargets; cs.OnLinkedByPlayer += SetEnemyTargets; cs.OnLinkedByPlayer += SetPlayerLink; cs.OnCutByPlayer += SetCut; cs.OnCutByEnemy += SetCut; hd.canHurtOther = false; if (cs.controller == Controller.Boss) { animator.SetTrigger("enemyLink"); } if (_incomingVelocity == Vector3.zero) { _incomingVelocity = Vector3.up; } canSetIncomingVelocity = true; }