예제 #1
0
 void Start()
 {
     // Get all AcidAttacks already on the player (this component should have at least been added)
     AcidAttack[] currentAttacks = gameObject.GetComponents<AcidAttack>();
     // If this component is not the only AcidAttack on the player
     if(currentAttacks.Length > 1)
     {
         for(int i  = 0; i < currentAttacks.Length; i++)
         {
             // Reset the timer if it is the original timer and not this timer
             if(currentAttacks[i] != this) currentAttacks[i].Timer.Reset();
         }
         // Destroy this AcidAttack because it is not the original
         Destroy(this);
     }
     // This is the only AcidAttack on the player
     else
     {
         // Initialize the acid attack
         controller = GetComponent<Controller>();
         t = gameObject.AddComponent<RepetitionTimer>();
         t.Initialize(damageInterval, "Acid Attack", numHits);
         t.TimeOut += new RepetitionTimer.TimerEvent(DamagePlayer);
         t.FinalTick += FinalHit;
     }
 }
예제 #2
0
        void Start()
		{
			controller = GetComponent<Controller>();
            // Get all AcidAttacks already on the player (this component should have at least been added)
            AcidAttack[] currentAttacks = gameObject.GetComponents<AcidAttack>();
            // If this component is not the only AcidAttack on the player
            if(currentAttacks.Length > 1)
            {
                for(int i  = 0; i < currentAttacks.Length; i++)
                {
                    // Reset the timer if it is the original timer and not this timer
                    if(currentAttacks[i] != this)
					{
						if(currentAttacks[i].Timer != null)
						{
							currentAttacks[i].Timer.Reset();
						}
						else
						{
							InitializeTimer();
						}
					}
                }
                // Destroy this AcidAttack because it is not the original
                Destroy(this);
            }
            // This is the only AcidAttack on the player
            else
            {
                // Initialize the acid attack
				InitializeTimer();
            }
        }
예제 #3
0
        void Update()
        {
            // Rotate the arrow towards the closest enemy if it is tracking
            if (trackingTime > 0)
            {
                // Find closest enemy player
                if (trackingTarget == null || !trackingTarget.GetComponent<Rigidbody>().isKinematic)
                {
                    trackingTarget = null;
                    float minDistance = 0f;
                    foreach (Controller player in GameManager.instance.AllPlayers)
                    {
                        float distance = Vector3.Distance(transform.position, player.transform.position);
                        if (!player.GetComponent<Rigidbody>().isKinematic 
                            && !player.ID.Equals(fromPlayer) && (trackingTarget == null || distance < minDistance))
                        {
                            trackingTarget = player;
                            minDistance = distance;
                        }
                    }
                }
                // Changes arrow direction
                if (trackingTarget != null)
                {
                    Vector3 direction = trackingTarget.transform.position - transform.position + new Vector3(0, 1, 0);
                    direction /= direction.magnitude;
                    float magnitude = rigidbody.velocity.magnitude;
                    // Ceiling used to prevent excess time from accumulating
                    //int iterations = Mathf.CeilToInt((trackingTime + Time.deltaTime) * 10) - Mathf.CeilToInt(trackingTime * 10);
                    //for (int i = 0; i < iterations; i++)
                    //{
                    // Alters direction - Modify last value to change tracking intensity
                    //rigidbody.velocity += direction * Mathf.Pow(magnitude, 2) / 25;
                    rigidbody.AddForce(direction * 200);
                    if (rigidbody.velocity.magnitude > 25) rigidbody.velocity /= magnitude * Time.deltaTime;
                        // Scales magnitude back to original
                        //rigidbody.velocity /= rigidbody.velocity.magnitude / magnitude;
                    //}
                }
                trackingTime -= Time.deltaTime;
                if (trackingTime <= 0)
                {
                    rigidbody.useGravity = true;
                }
            }
            // Point the arrow the direction it is travelling
            if (rigidbody != null && rigidbody.velocity != Vector3.zero)
            {
                transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
                // Cache the previous velocity
                prevVelocity = rigidbody.velocity;
            }
			if (transform.position.y < -30) 
			{
				GameObject.Destroy(gameObject);
			}
        }
예제 #4
0
        /// <summary>
        ///  Override the TokenCollected method and tell the Archery component to collect the token
        /// </summary>
        /// <param name="controller">The controller that is doing the collecting</param>
        public override void TokenCollected(Controller controller)
        {
            if (controller.ArcheryComponent.CanCollectToken() && !Util.Bitwise.IsBitOn(controller.ArcheryComponent.ArrowTypes, (int)type))
            {
                controller.ArcheryComponent.CollectToken(this);
                // Set inactive since we are pooling
				collected = true;
				GetComponent<Collider>().enabled = false;
            }
        }
예제 #5
0
		void Start()
		{
			damage = 0f;

			fromController = GameManager.instance.GetPlayer(fromPlayer);
			hitController = GameManager.instance.GetPlayer(hitPlayer);

			transform.position = hitController.transform.position + fromUp;

			lights = new Dictionary<Enums.Arrows, GameObject>();
			for(int i = 1; i < (int) Enums.Arrows.NumTypes; i++)
			{
				if(Bitwise.IsBitOn(hitController.ArcheryComponent.ArrowTypes, i))
				{
					//hitController.ArcheryComponent.RemoveArrowType((Enums.Arrows) i);

					GameObject light;
					if(lights.Count > transform.childCount)
					{
						light = (GameObject) Instantiate(transform.GetChild(0).gameObject);
					}
					else
					{
						light = transform.GetChild(0).gameObject;
					}

					float r = ((float) i / ((float) Enums.Arrows.NumTypes - 1)) % 1f;
					float g = (0.33f + (float) i / ((float) Enums.Arrows.NumTypes - 1)) % 1f;
					float b = (0.67f + (float) i / ((float) Enums.Arrows.NumTypes - 1)) % 1f;
					light.GetComponent<Light>().color = new Color(r, g, b);
						
					light.transform.SetParent(transform);
					light.transform.localPosition = Vector3.zero;
					light.GetComponent<Rigidbody>().AddForce(randomInSemicircle(hitUp) * explodeForce, ForceMode.Impulse);
					lights.Add((Enums.Arrows) i, light);
				}
			}

            hitController.ArcheryComponent.ArrowTypes = hitController.ArcheryComponent.PermanentArrowTypes;
				
			if(lights.Count == 0) 
			{
				Destroy(gameObject);
			}
		}
		// Method to broadcast to the controller to all components
		protected void AssignController(Controller controller)
		{
			this.controller = controller;
		}
예제 #7
0
파일: Token.cs 프로젝트: dvalles/Rangers
 /// <summary>
 /// Token will use the Controller to get the appropriate component
 /// </summary>
 /// <param name="controller">The controller that is collecting the token</param>
 protected abstract void TokenCollected(Controller controller);
예제 #8
0
 /// <summary>
 /// Override the TokenCollected method and tell the Life component to collect the token
 /// </summary>
 /// <param name="controller">Controller that is collecting the token</param>
 public override void TokenCollected(Controller controller)
 {
     controller.LifeComponent.CollectToken(this);
     // Set inactive since we are pooling
     gameObject.SetActive(false);
 }
예제 #9
0
        /// <summary>
        ///  Override the TokenCollected method and tell the Archery component to collect the token
        /// </summary>
        /// <param name="controller">The controller that is doing the collecting</param>
        protected override void TokenCollected(Controller controller)
        {
			controller.ArcheryComponent.CollectToken(this);
        }
예제 #10
0
        // Tokens will be collected via trigger
        //void OnTriggerEnter(Collider col)
        //{
		//	TokenCollected(col.transform.root.GetComponent<Controller>());
        //}

        /// <summary>
        /// Token will use the Controller to get the appropriate component
        /// </summary>
        /// <param name="controller">The controller that is collecting the token</param>
        public abstract void TokenCollected(Controller controller);