public void DropItem(int slotIndex) { if (!GetItem(slotIndex).Data.IsRemoveable) { return; } isDirty = true; LootableItem lootable = droppableItemPrefab.Retrieve <LootableItem>(); if (lootable != null) { Aimer getAimer = this.GetComponent <Aimer>(); Vector2 aimDirection = Vector2.zero; if (getAimer != null) { aimDirection = getAimer.GetAimDirection(); } lootable.transform.position = (Vector2)this.transform.position + (aimDirection * (lootable.PickupDistance() * 1.05f)); lootable.Configure(GetItem(slotIndex).Data, GetItem(slotIndex).Amount); lootable.gameObject.SetActive(true); foreach (var dispatcher in eventDispatchers.Values) { dispatcher.DispatchDropItem(slotIndex, lootable); } } RemoveItem(slotIndex); }
public override void OnInspectorGUI() { Aimer aimer = target as Aimer; /* * PrefabShooter shooter = aimer.GetComponent<PrefabShooter>(); * m_gunObject.Enabled = ((shooter == null) || !shooter.enabled); * m_gunObject.HelpText = m_gunObject.Enabled * ? "This is the object that will be aimed to point in the firing direction.\n" + * "If this is left blank, the parent GameObject will be used." * : "This field is currently disabled as the firing object is being set by the PrefabShooter also on this object.\n" + * "To change this field, either disable or remove the PrefabShooter from the gameobject."; */ Limiter limits = aimer.GetComponent <Limiter>(); m_applyToBarrel.Enabled = ((limits == null) || !limits.enabled); if (aimer.m_applyAimToBarrel && !m_applyToBarrel.Enabled) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterUndo(aimer, "Apply to barrel " + aimer.name); #else Undo.RecordObject(aimer, "Apply to barrel " + aimer.name); #endif aimer.m_applyAimToBarrel = false; } aimer.m_applyAimToBarrel &= m_applyToBarrel.Enabled; m_applyToBarrel.HelpText = m_applyToBarrel.Enabled ? "Whether or not apply the aim directly to the gun object" : "This field is currently disabled as it is being set by the AimerLimits component also on this object.\n" + "To change this field, wither disable or remove the AimerLimits from the gameobject."; m_applyToBarrel.FalseHelp = m_applyToBarrel.Enabled ? "FALSE: The gun object will not be aimed - it is up to the user (or another script) to access the AimDirection property to do the aiming." : ""; m_maxIterations.Enabled = ((aimer.m_targetType != Aimer.TargetPredictionType.Linear) || (aimer.m_projectileType != Aimer.ProjectilePredictionType.Linear)); m_maxIterations.HelpText = m_maxIterations.Enabled ? "The maximum number of iterations the solver will take to aim." : "This value is not used when both target and projectile predictor types are linear, as a faster analytic method is used to aim."; m_maximumInaccuracy.Enabled = m_maxIterations.Enabled; m_maximumInaccuracy.HelpText = m_maximumInaccuracy.Enabled ? "How close to the centre of the target the iterative solver has to get." : "This value is not used when both target and projectile predictor types are linear, as a faster analytic method is used to aim."; m_editHelp.EditProperties(aimer); if (Application.isPlaying) { bool enabled = GUI.enabled; GUI.enabled = false; EditorGUILayout.IntField("DEBUG: Iterations used", aimer.m_iterationsUsed); GUI.enabled = enabled; } }
public void ExitAim() { if (DisableAim) { Aimer.Active = false; } else { Aimer.ExitAim(); } }
public void Awake() { m_RigidBody2D = this.GetComponent <Rigidbody2D>(); m_Animator = this.GetComponent <Animator>(); m_SpriteRenderer = GetComponentInChildren <SpriteRenderer>(); m_Aimer = GetComponentInChildren <Aimer>(); if (meleePos != null) { m_HitboxRange = meleePos.localPosition.x; } }
///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> This method is used to activate the AIM mode when the right click is pressed</summary> public virtual void SetHorizontalAngle() { if (!Aimer.Active) { Aimer.Calculate(); //Recalculate when the Aimer is not Active } float NewHorizontalAngle = Aimer.HorizontalAngle / 180; //Get the Normalized value for the look direction HorizontalAngle = Mathf.Lerp(HorizontalAngle, NewHorizontalAngle, Time.fixedDeltaTime * 10f); //Smooth Swap between 1 and -1 SetFloatParameter(Hash_WAim, HorizontalAngle); }
// Start is called before the first frame update void Awake() { lenRope = 1.8f; curSpeed = maxSpeed; aimer = aimerObj.GetComponent <Aimer>(); m_Rigidbody2D = GetComponent <Rigidbody2D>(); m_CharacterController2D = GetComponent <CharacterController2D>(); playerInput = GetComponent <PlayerInput>(); m_Animator = GetComponent <Animator>(); m_Animator.SetFloat(m_HashDirectionPara, 1); m_PlayerAudio = GetComponent <PlayerAudio>(); }
/// <summary> Start the Main Attack Logic </summary> public virtual void MainAttack() { if (WeaponIsActive) { if (!Aimer.Active) { Aimer.Calculate(); //Quick Aim Calculation in case the Aimer is Disabled } Weapon.MainAttack_Start(this); OnMainAttackStart.Invoke(Weapon.gameObject); } }
public void ApplyTurret() { Aimer aimer = m_baseObject.AddComponent <Aimer>(); aimer.m_gunObject = m_gunBarrelObject; if (m_swivel) { aimer.m_optionalSwivel = m_swivelObject; } if (m_projectileHasGravity) { aimer.m_projectileType = Aimer.ProjectilePredictionType.Parabolic; } else { aimer.m_projectileType = Aimer.ProjectilePredictionType.Linear; } aimer.m_targetType = m_targetType; if (m_hasLimits) { m_baseObject.AddComponent <Limiter>(); aimer.m_applyAimToBarrel = false; } else { aimer.m_applyAimToBarrel = true; } if (m_hasTargeter) { Targeter targeter = m_baseObject.AddComponent <Targeter>(); targeter.m_targetTag = m_targetTag; } if (m_hasShooter) { PrefabShooter shooter = m_baseObject.AddComponent <PrefabShooter>(); shooter.m_bulletPrefab = m_bulletPrefab; } Close(); Selection.activeGameObject = m_baseObject; EditorUtility.DisplayDialog("Turret settings applied", "The settings have been applied to your turret!\n" + "Don't forget all settings in the inspector have help that can be " + "viewed by clicking on the little '?' to their right.", "OK"); }
private void Start() { _aimer = GetComponent <Aimer>(); _shooter = GetComponent <Shooter>(); _playerTransform = FindObjectOfType <PlayerInput>().transform; var shootingSubscription = AIHelper.GetTimerStreamWithRandomStart(_shootingFrequencity) .Where(_ => PlayerIsNear) .Subscribe(_ => Fire()); GetComponent <UnitHealth>().HealthPercentageStream.Subscribe(_ => { }, () => { shootingSubscription.Dispose(); enabled = false; }); gameObject.OnDestroyAsObservable().Subscribe(_ => shootingSubscription.Dispose()); }
public Bot() { grabber = null; detector = null; tracker = null; selector = null; injector = null; aimer = null; trigger = null; stopwatch = new Stopwatch(); activationKey = ActivationKeys.None; activationButton = ActivationButtons.None; process = null; time = 0.0; activated = false; disposed = false; }
public void OnSceneGUI() { // make sure we detect any changes in the object GUI.changed = false; PrefabShooter shooter = target as PrefabShooter; Aimer aimer = shooter.GetComponent <Aimer>(); if (!aimer || !aimer.m_gunObject) { return; } Matrix4x4 handlesMatrix = Handles.matrix; Handles.matrix = aimer.m_gunObject.transform.localToWorldMatrix; Color oldColor = Handles.color; Handles.color = Color.red; foreach (PrefabShooter.ExitPoint point in shooter.m_exitPoints) { Handles.DrawWireDisc(point.firingOffset, Vector3.forward, 0.2f); point.firingOffset = Handles.PositionHandle(point.firingOffset, Quaternion.identity); } Handles.color = oldColor; Handles.matrix = handlesMatrix; // report any changes in the object. if (GUI.changed) { EditorUtility.SetDirty(shooter); } }
public override IEnumerator ItemUseAction(Inventory userInventory, int itemIndex) { Aimer getAimer = userInventory.GetComponent <Aimer>(); Mover getMover = userInventory.GetComponent <Mover>(); //GridSelector getGridSelector = userInventory.GetComponent<GridSelector>(); if (getMover.IsMovementFrozen) { yield break; } Vector2 attackLocation = (Vector2)userInventory.transform.position + (getAimer.GetAimDirection() * attackDistance); //Vector2 attackLocation = getGridSelector.GetGridWorldSelectionPosition(); getAimer.LookAt(attackLocation); BodyAnimation[] getEntityAnimator = userInventory.GetComponentsInChildren <BodyAnimation>(); float animationTime = 0; for (int i = 0; i < getEntityAnimator.Length; i++) { switch (attackType) { case AttackType.Smash: animationTime = getEntityAnimator[i].ApplySmashAnimation(speed, userInventory.GetItem(itemIndex).Data.Icon); break; case AttackType.Slash: animationTime = getEntityAnimator[i].ApplySlashAnimation(speed, userInventory.GetItem(itemIndex).Data.Icon); break; default: break; } } getMover.FreezeMovement(true); yield return(new WaitForSeconds(animationTime * 0.5f)); GameObject damageVolume = damageVolumePool.Retrieve(attackLocation, new Quaternion()); damageVolume.GetComponent <DamageVolume>().Configure(new DamageVolumeConfiguration() { Damage = damage, Owner = userInventory.gameObject, ActiveTime = 0.5f, TargetTags = targetTags, AllowDuplicateDamage = true, CanDamageMultiple = hitMultipleTargets, Size = new Vector2(0.10f, 0.10f) }); yield return(new WaitForSeconds(animationTime * 0.5f)); getMover.FreezeMovement(false); yield return(null); }
// Use this for initialization void Start() { time += Time.time; aa = GameObject.Find("Aimer").GetComponent <Aimer> (); }
/// <summary> /// Pre-iniitalization /// </summary> void Awake() { if (instance == null) instance = this; else if (instance != this) Destroy(gameObject); //Initialize the board board = GetComponentInChildren<Board>(); //Initialize player player = transform.FindChild ("Player").GetComponent<Player> (); //Grab the aimer game objects aimer = transform.FindChild("Aimer").GetComponent<Aimer>(); //Set the Player Attributes player.setAttack(10); }
// Update is called once per frame void Update() { float currentTime = Time.time; float timeElapsed = currentTime - startTime; accuracy = Mathf.RoundToInt((float)currentWaypointIndex / (float)numWaypoints * 100); if (!isGameOver && (timeElapsed >= timeLimit)) { isGameOver = true; endTime = Time.time; timedOut = true; } if (!isGameOver) { //If left mouse button is clicked if (Input.GetMouseButton(0)) { //Get mouse position in screen space Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 4.9f); //Get mouse position in world space Vector3 mouseWorldPos = player.GetComponent <Player>().playerCamera.GetComponent <Camera>().ScreenToWorldPoint(mousePos); if (distance(mouseWorldPos, waypoints[currentWaypointIndex].transform.position) < 0.25) { color_progress[currentWaypointIndex]++; currentWaypointIndex++; if (currentWaypointIndex >= numWaypoints) { isGameOver = true; endTime = Time.time; } } for (int k = 0; k < numWaypoints; k++) { if (color_progress[k] > 0 && color_progress[k] < 25) { waypoints[k].GetComponent <Renderer>().material.SetColor("_Color", Color.Lerp(starting_colors[k], Color.magenta, color_progress[k] / 25.0f)); color_progress[k]++; } } GameObject trace = Instantiate(traceAsset, mouseWorldPos, traceAsset.transform.rotation); trace.GetComponent <Renderer>().material.SetColor("_Color", Color.cyan); trace.transform.localScale = new Vector2(0.3f, 0.3f); traceList.Add(trace); if (previousCursor != null) { Destroy(previousCursor); } cursor = Instantiate(cursorAsset, mouseWorldPos, cursorAsset.transform.rotation); cursor.GetComponent <Renderer>().material.SetColor("_Color", Color.cyan); cursor.transform.localScale = new Vector2(1.2f, 1.2f); previousCursor = cursor; } } else { if (!timedOut) { for (int k = 0; k < numWaypoints; k++) { waypoints[k].GetComponent <Renderer>().material.SetColor("_Color", Color.magenta); } } if (currentTime - endTime > 3) { //Debug.Log("ACCURACY: " + accuracy + "%"); Destroy(cursor); for (int p = 0; p < numWaypoints; p++) { Destroy(waypoints[p]); } for (int q = 0; q < traceList.Count; q++) { Destroy((GameObject)traceList[q]); } player.GetComponent <Player>().status.accuracy = accuracy; Aimer aimer = Instantiate(Resources.Load("Aimer") as GameObject).GetComponent <Aimer>(); aimer.cam = player.GetComponent <Player>().playerCamera.GetComponent <Camera>(); aimer.spell = spell; aimer.gameMaster = gameMaster; aimer.player = player.GetComponent <Player>(); aimer.targetList = player.GetComponent <TargetList>(); player.GetComponent <TargetList>().CmdClear(); aimer.startFollowing = true; // gameMaster.spellButtonsEnabled = true; Destroy(gameObject); } } }