This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

fpsarmedunity

Member
  • Content count

    40
  • Joined

  • Last visited

Community Reputation

4 Neutral

About fpsarmedunity

  • Rank
    Member
  • Birthday 11/20/1950

Profile Information

  • Gender
    Male
  • Location:
    World
  1. figured by myself... solved... can someone tell me a simple way to ad tooltip when inventory slot is highlighted??
  2. Hi i have i question.. I'm using fpskit as base of my project and i'm integrating an inventory system with pickup etc.. all works fine and only issue is that wheni close my inventory lockcursor remain in Cursor.lockState = CursorLockMode.None; and dont give me the full control of the player here a video of what happen here the lockcursor script i'm using using UnityEngine; using System.Collections; public class LockCursor : MonoBehaviour { // FPS KIT [www.armedunity.com] void Start() { Application.targetFrameRate = 120; #if UNITY_EDITOR Cursor.visible = true; Cursor.lockState = CursorLockMode.Locked; #else Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; #endif } void OnGUI() { if (Event.current.type == EventType.KeyDown) { /* if (Event.current.keyCode == KeyCode.P){ Screen.SetResolution (1920, 1080, true); Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } */ if (Event.current.keyCode == KeyCode.I) { Cursor.visible = true; } } /* if (Cursor.lockState == CursorLockMode.None) { if (GUI.Button(new Rect(Screen.width - 120, 20, 100, 30), "Lock Cursor")) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } } */ } } and there the inventory.cs script using UnityEngine; using System.Collections; using System.Collections.Generic; public class Inventory : MonoBehaviour { public int verticalSlots; public int horizontalSlots; public float slotSizeX; public float slotSizeY; [HideInInspector] public bool showInventory; [HideInInspector] public bool userHasOption = false; public Texture2D emptySlotTexture; public KeyCode inventoryInput; public GUISkin guiSkin; public List<Slot> inventory; private bool dragging = false; private GameObject equipedObject = null; private Vector2 windowPosition = Vector2.zero; private Vector2 windowSize = Vector2.zero; private Vector2 clickMousePosition = Vector2.zero; private Slot dragSlot = new Slot(); private Slot receiver = new Slot(); private PlayerInteraction playerInteraction = null; // Represents an Inventory Slot. public struct Slot { public int id; // Identifier used to find this Slot. public int itemID; // Returns the actual amount of Items inside this Slot. public int stacks { get { return slotObjects.Count; } } // Returns if we have more then one Item inside this Slot. public bool stackableSlot { get { return slotObjects.Count > 1; } } public List<GameObject> slotObjects; public Texture2D slotTexture; public Rect originalRect; public Rect currentRect; // Returns a bool indicating if this slots original Rect contains <cursorPosition>. public bool Contains (Vector2 cursorPosition) { return this.originalRect.Contains(cursorPosition); } // Returns a bool indicating if this slot is outside the GUI Windows Rect. public bool OutsideWindow (Vector2 windowPosition, Vector2 windowSize) { Rect windowRect = new Rect(windowPosition.x, windowPosition.y, windowSize.x, windowSize.y); return !windowRect.Contains(Event.current.mousePosition); } } private void OnValidate () { if (verticalSlots < 1) verticalSlots = 1; if (horizontalSlots < 1) horizontalSlots = 1; if (slotSizeY < 1) slotSizeY = 1; if (slotSizeX < 1) slotSizeX = 1; } private void Start () { // Find our PlayerInteraction MonoBehaviour on our Player Camera GameObject. //playerInteraction = transform.Find("MainCamera").GetComponent<PlayerInteraction>(); playerInteraction = GameObject.FindWithTag("MainCamera").transform.GetComponent<PlayerInteraction>(); // Inicialize our <inventory> List with a set <inventorySize> capacity. inventory = new List<Slot>(horizontalSlots * verticalSlots); // Calculate the <windowSize> based on the <slotSize> and the amount of slots. windowSize = new Vector2(horizontalSlots * slotSizeX, verticalSlots * slotSizeY); // Calculate the <windowPosition> based on <windowSize>. windowPosition = new Vector2((Screen.width - windowSize.x) / 2, (Screen.height - windowSize.y) / 2); // Our current (X,Y) positions inside our GUI Window. float currentX = windowPosition.x; float currentY = windowPosition.y; // Add an empty slot for each available slot in the <inventory>. for (int i = 0; i < inventory.Capacity; i++) { Slot emptySlot = new Slot(); emptySlot.id = i; emptySlot.itemID = 0; emptySlot.slotObjects = new List<GameObject>(); emptySlot.slotTexture = emptySlotTexture; emptySlot.originalRect = new Rect(currentX, currentY, slotSizeX, slotSizeY); emptySlot.currentRect = emptySlot.originalRect; // Move horizontally by <slotSize>. currentX += slotSizeX; // Check if we can fit another Slot horizontally. if (currentX + slotSizeX > windowPosition.x + windowSize.x) { // If we cannot fit another slot horizontally then move vertically and // reset our horizontal position. currentX = windowPosition.x; currentY += slotSizeY; } inventory.Add(emptySlot); } } private void Update () { // Show or hide this inventory. if (Input.GetKeyDown(inventoryInput)) { showInventory = !showInventory; Cursor.visible = showInventory; //Cursor.visible = true; Cursor.lockState = CursorLockMode.None; GetComponent<MouseLook>().enabled = !showInventory; //tranform.Find("Camera").GetComponent<MouseRotation>().enabled = !showInventory; //GameObject.FindWithTag("MouseLook").GetComponent<MouseLook>().enabled = !showInventory; GameObject.Find("MouseLook").GetComponent<MouseLook>().enabled = !showInventory; } } private void OnGUI () { GUI.skin = guiSkin; if (showInventory) { // The Inventory's Header. GUI.Box(new Rect(windowPosition.x, windowPosition.y - 25, windowSize.x, 30), "Inventory"); // The Inventory's Window. GUI.Box(new Rect(windowPosition.x, windowPosition.y, windowSize.x, windowSize.y), ""); for (int i = 0; i < inventory.Count; i++) { if (inventory[i].stackableSlot) { // If this slot is stackable then draw a label counting the amount of // stacks and disable the ability to equip this stackable item. string stackLabel = string.Format("<b><size=20>{0}</size></b>", inventory[i].stacks); // Stackable items are not equipable. GUI.Button(inventory[i].currentRect, inventory[i].slotTexture); // Only show the stack amount label is we have more then 1 item stacked. if (inventory[i].stacks > 0) GUI.Label(inventory[i].currentRect, stackLabel); } else { // If we click this Slot Button then equip the GameObject it holds. if (GUI.Button(inventory[i].currentRect, inventory[i].slotTexture) && !userHasOption) { Item slotItem = inventory[i].slotObjects[0].GetComponent<Item>(); if (inventory[i].slotObjects.Count > 0 && slotItem.usable) { GameObject slotObject = inventory[i].slotObjects[0]; slotObject.SendMessage("InventoryUse", SendMessageOptions.DontRequireReceiver); Destroy(inventory[i].slotObjects[inventory[i].slotObjects.Count - 1]); inventory[i].slotObjects.RemoveAt(inventory[i].slotObjects.Count - 1); if (inventory[i].slotObjects.Count < 1) inventory[i] = ResetSlot(inventory[i]); } } } // If the mouse is inside this Slot then watch for dragging. if (inventory[i].Contains(Event.current.mousePosition) && !dragging) { // If we click with the left mouse button set its click screen position; if (Input.GetMouseButtonDown(0)) { clickMousePosition = Event.current.mousePosition; } // If we clicked then moved our mouse that means we are dragging the slot. if (Input.GetMouseButton(0) && Event.current.mousePosition != clickMousePosition) { // Prevent the Player from dragging empty slots. if (inventory[i].slotObjects.Count > 0) { dragSlot = inventory[i]; dragging = true; } } } if (dragging) { if (Input.GetMouseButtonUp(0)) { // If we released our left mouse button and the Slots Rect is // outside the Window, then drop the item it contained. if (dragSlot.OutsideWindow(windowPosition, windowSize)) { if (dragSlot.slotObjects.Count > 0) { Item item = null; if (dragSlot.stackableSlot) { // If we are a stackable Slot then we drop 1 of the stacked items. if (dragSlot.slotObjects.Count == 1) { // If we only have 1 GameObject left then drop it and restore this // slot to a normal empty slot. item = dragSlot.slotObjects[0].GetComponent<Item>(); dragSlot = ResetSlot(dragSlot); } else { int lastItemIndex = dragSlot.slotObjects.Count - 1; item = dragSlot.slotObjects[lastItemIndex].GetComponent<Item>(); dragSlot.slotObjects.RemoveAt(lastItemIndex); } } else { // If the Slot we dragged out of the Window is not stackable // then just drop the item it contained. item = dragSlot.slotObjects[0].GetComponent<Item>(); dragSlot = ResetSlot(dragSlot); if (equipedObject != null) { equipedObject.SetActive(false); equipedObject = null; } } item.DropItem(); // Since we are modifying this Slot inside the main foreach loop // calling UpdateSlotData() would be extremelly slow due to a // loop inside another loop. inventory[inventory[i].id] = inventory[i]; } } else { // If we dropped the Item inside the Window, check what Slot we dropped // it upon. for (int y = 0; y < inventory.Count; y++) { // If this instance is the <dragSlot> itself then skip it. if (inventory[y].id == dragSlot.id) continue; // If we found a Slot that contains the mouse then exchange // Slot information from the <dragSlot> to the <receiverSlot> // and the <receiverSlot> to the <dragSlot>. if (inventory[y].Contains(Event.current.mousePosition)) { receiver = inventory[y]; userHasOption = true; break; } } } // If we got our left mouse button up return the <dragSlot> // to its original position. dragSlot.currentRect = dragSlot.originalRect; // Update the <dragSlot>'s data. UpdateSlotData(dragSlot); // And since we released the left mouse button we are no longer dragging. dragging = false; break; } // If we are dragging then set the <dragSlot>'s position to be the current // mouse cursor's position (Compensating for the <slotSize> offset). dragSlot.currentRect.x = Event.current.mousePosition.x - 35; dragSlot.currentRect.y = Event.current.mousePosition.y - 35; // If the current slot being iterated is the <dragSlot> then update its info. if (inventory[i].id == dragSlot.id) inventory[inventory.IndexOf(inventory[i])] = dragSlot; } } if (userHasOption) { // Prompt the Player if he wants to create whatever the combination // of both items can create or just exchange Slots. if (receiver.slotObjects.Count == 0) { if (dragSlot.stackableSlot && dragSlot.stacks > 1) { Rect button1Rect = new Rect(Screen.width - windowPosition.x, Screen.height - windowPosition.y - 80, 150, 40); Rect button2Rect = new Rect(Screen.width - windowPosition.x, Screen.height - windowPosition.y - 40, 150, 40); if (GUI.Button(button1Rect, "Move Stack")) { receiver.itemID = dragSlot.itemID; receiver.slotObjects = dragSlot.slotObjects; receiver.slotTexture = dragSlot.slotTexture; dragSlot.itemID = 0; dragSlot.slotObjects = new List<GameObject>(); dragSlot.slotTexture = emptySlotTexture; UpdateSlotData(receiver); UpdateSlotData(dragSlot); userHasOption = false; } if (GUI.Button(button2Rect, "Seperate Stack")) { receiver.itemID = dragSlot.itemID; receiver.slotObjects.Add(dragSlot.slotObjects[dragSlot.slotObjects.Count - 1]); receiver.slotTexture = dragSlot.slotTexture; dragSlot.slotObjects.RemoveAt(dragSlot.slotObjects.Count - 1); UpdateSlotData(receiver); UpdateSlotData(dragSlot); userHasOption = false; } } else { ExchangeSlots(dragSlot, receiver); userHasOption = false; } } else { Rect button1Rect = new Rect(Screen.width - windowPosition.x, Screen.height - windowPosition.y - 120, 150, 40); Rect button2Rect = new Rect(Screen.width - windowPosition.x, Screen.height - windowPosition.y - 80, 150, 40); Rect button3Rect = new Rect(Screen.width - windowPosition.x, Screen.height - windowPosition.y - 40, 150, 40); // GUI Button for combining 2 Slot items. CraftingCombinations crafting = this.GetComponent<CraftingCombinations>(); string craftableItem = ""; int newItemID = 0; foreach (CraftingCombinations.ItemCombination combination in crafting.itemCombinations) { int combinationSum = (combination.itemID1 * 10) + combination.itemID2; int inventorySum = (dragSlot.itemID * 10) + receiver.itemID; if (combinationSum == inventorySum) { craftableItem = combination.name; newItemID = combinationSum; } } if (newItemID != 0) { // GUI Button for crafting items. if (GUI.Button(button3Rect, "Craft " + craftableItem)) { GameObject craftedObject = Resources.Load<GameObject>(craftableItem); GameObject craftedInstance = (GameObject)Instantiate(craftedObject); craftedInstance.name = craftableItem; CraftItem(craftedInstance, newItemID); } } // GUI Button for swaping Slots. if (GUI.Button(button2Rect, "Swap Items")) { ExchangeSlots(dragSlot, receiver); userHasOption = false; } // GUI Button for stacking Slots. if (receiver.itemID == dragSlot.itemID) { if (GUI.Button(button1Rect, "Stack Items")) { receiver.slotObjects.Add(dragSlot.slotObjects[dragSlot.slotObjects.Count - 1]); dragSlot.slotObjects.RemoveAt(dragSlot.slotObjects.Count - 1); if (dragSlot.slotObjects.Count < 1) { for (int i = 0; i < inventory.Count; i++) { if (inventory[i].id == dragSlot.id) { inventory[i] = ResetSlot(inventory[i]); break; } } } userHasOption = false; } } } } } } public void CraftItem (GameObject craftedObject, int newItemID) { Item craftedItem = craftedObject.GetComponent<Item>(); // Remove the item from the <dragSlot>. if (dragSlot.slotObjects.Count > 0) { Destroy(dragSlot.slotObjects[dragSlot.slotObjects.Count - 1]); if (dragSlot.stacks > 1) { dragSlot.slotObjects.RemoveAt(dragSlot.slotObjects.Count - 1); } else { dragSlot = ResetSlot(dragSlot); } } // Remove the item from the <receiver> Slot. if (receiver.slotObjects.Count > 0) { Destroy(receiver.slotObjects[receiver.slotObjects.Count - 1]); if (receiver.stacks > 1) { receiver.slotObjects.RemoveAt(receiver.slotObjects.Count - 1); } else { receiver = ResetSlot(receiver); } craftedItem.PickupItem(this.transform); if (InventoryHasSpace()) { Slot slot = new Slot(); for (int i = 0; i < inventory.Count; i++) { slot = inventory[i]; if (slot.itemID == 0) { slot.itemID = newItemID; slot.slotTexture = craftedItem.slotIcon; slot.slotObjects.Add(craftedObject); break; } } UpdateSlotData(slot); } else { craftedItem.DropItem(); } } UpdateSlotData(receiver); UpdateSlotData(dragSlot); userHasOption = false; } public bool InventoryHasSpace() { foreach (Slot slot in inventory) { if (slot.slotObjects.Count == 0) return true; } return false; } public void AddItem (Item item) { if (!InventoryHasSpace()) { Debug.Log("No available slots in inventory for " + item.name + " to be added."); return; } Slot editSlot = new Slot(); // If this item is stackable then find a Slot with its similar // GameObject type and stack it, if there is none, just add it. if (item.maxStackAmount > 1) { // Search for any stackable Slots with the same GameObject type as // the one we want to add. List<Slot> stackableSlots = FindSlot(item.itemID); if (stackableSlots.Count > 0) { foreach (Slot stackableSlot in stackableSlots) { if (stackableSlot.stacks < item.maxStackAmount) { // If we found a stackable Slot with the same GameObject type as // the one we want to add, then add another stack to that slot. // If this is the Slots first stack set it to stackable. stackableSlot.slotObjects.Add(playerInteraction.currentObject); editSlot = stackableSlot; break; } } if (editSlot.itemID == 0) editSlot = AddToEmptySlot(item); } else { // If we do not already contain this GameObject type then just add it. editSlot = AddToEmptySlot(item); } } else { // If this item is not stackable then just add it to an empty Slot. editSlot = AddToEmptySlot(item); } // Pickup the item we were interacting with. item.PickupItem(this.transform); // Update the actual inventory Slot. UpdateSlotData(editSlot); } private Slot ResetSlot (Slot slot) { slot.itemID = 0; slot.slotObjects = new List<GameObject>(); slot.slotTexture = emptySlotTexture; return slot; } // Exchanges information between the <sender> and <receiver> Slots. private void ExchangeSlots(Slot sender, Slot receiver) { // Check if the <sender> has any information to exchange, otherwise // there is no reason to exchange Nothing for Nothing. if (sender.slotObjects.Count > 0) { Slot oldSender = sender; // Change the <dragSlot>'s information to the ones the <receiver> Slot had. sender.itemID = receiver.itemID; sender.slotObjects = receiver.slotObjects; sender.slotTexture = receiver.slotTexture; // Change the <receiver>'s information to the ones the <dragSlot> had. receiver.itemID = oldSender.itemID; receiver.slotObjects = oldSender.slotObjects; receiver.slotTexture = oldSender.slotTexture; UpdateSlotData(sender); UpdateSlotData(receiver); } } // Finds the next available empty Slot. private Slot FindSlot() { foreach (Slot slot in inventory) { if (slot.slotObjects.Count == 0) return slot; } return new Slot(); } // Finds the slot that contains a GameObject with the same // type as the <objectName>. private List<Slot> FindSlot(int objectID) { List<Slot> foundSlots = new List<Slot>(); foreach (Slot slot in inventory) { if (slot.itemID == objectID) foundSlots.Add(slot); } return foundSlots; } // Finds the <target> Slot inside the Inventory by using its id. private void UpdateSlotData (Slot target) { for (int i = 0; i < inventory.Count; i++) { if (inventory[i].id == target.id) inventory[i] = target; } } private Slot AddToEmptySlot (Item item) { Slot editSlot = FindSlot(); if (editSlot.slotObjects.Count == 0) { // Add the GameObject we were interacting with to the slot. editSlot.slotObjects.Add(playerInteraction.currentObject); editSlot.slotTexture = item.slotIcon; editSlot.itemID = item.itemID; } return editSlot; } }
  3. sorry i found this thread from the search and did not saw the section.. sorry again...
  4. where did you see the brakeys inventory c# versio worked with fpskit?? cna you link it?' thanks
  5. cant wait
  6. mant thanks for your guide...
  7. thanks for the guide but my model has only one animation named take001 ..here the pic ..is the same or i misunderstood something?
  8. great... many thanks ..i really appreciate your help.. one last question. i downloadec a couterstrike paxk with models ,weapons etc and i want to use it for my testing and learnig pourposes .. but i noticed that characters in it are with not standard legacy animations but the have an avatar and a single animation named "take001" that i think is an animation clip how can i use them lke legacy and have single animations like , idle, run ,walk ,shoot .ect.??
  9. hi i downloaded a cs resource pack from the net for learning pourposes with characters weapons etc .but characters dont have legacy anmimations but avatar and mecanim i suppose.. but i dont knowhow to set animations with mecanim .. can please someone could tell me how i cas use these asset ??
  10. ok many thanks for you great answer ..i'll try to follow your instructions and try to use volocity cheks but i really cannot figured out.. LOL
  11. maybe i misunderstood something or my bad english make my day but i was referring to agent ai animations so what mean "character controller" ??? btw i forgot to post my animation script named AiAnimation var minimumRunSpeed = 1.0; function Start () { // Set all animations to loop GetComponent.<Animation>().wrapMode = WrapMode.Loop; // Except our action animations, Dont loop those GetComponent.<Animation>()["shoot"].wrapMode = WrapMode.Once; // Put idle and run in a lower layer. They will only animate if our action animations are not playing GetComponent.<Animation>()["idle"].layer = -1; GetComponent.<Animation>()["walk"].layer = -1; GetComponent.<Animation>()["run"].layer = -1; GetComponent.<Animation>().Stop(); } function SetSpeed (speed : float) { if (speed > minimumRunSpeed) GetComponent.<Animation>().CrossFade("run"); else GetComponent.<Animation>().CrossFade("walk"); }
  12. thanks for your reply .. but i was thinking i was able to set the animation to run direclty in the scirpt i posted above e.g. whem agent "see" the player it start "run " towards the player and so on..
  13. Hi I'm integrating a very simple ai into my project and i'm using fps tutorial from nutiy converted by oma... I managed to make my agents to work and i can kill them and they can kill me etc.. but i cannot figured how i can have differet animations fro walk an run when i need them.. i have this script for my agent ai var Damage : float = 1; var speed = 3.0; var rotationSpeed = 5.0; var shootRange = 15.0; var attackRange = 30.0; var shootAngle = 10.0; var dontComeCloserRange = 5.0; var delayShootTime = 0.35; var pickNextWaypointDistance = 2.0; var target : Transform; private var lastShot = -10.0; //Modifications private var hitParticles : ParticleEmitter; var muzzleFlash : Renderer; var bulletsPerClip = 40; var clips = 20; var reloadTime = 0.5; private var bulletsLeft : int = 0; private var nextFireTime = 0.0; private var m_LastFrameShot = -1; var force = 10.0; var range = 100.0; var chasing : boolean = false; // Make sure there is always a character controller @script RequireComponent (CharacterController) function Start () { // Auto setup player as target through tags //if (target == null && GameObject.FindWithTag("Player")) target = GameObject.FindWithTag("Player").transform; hitParticles = GetComponentInChildren(ParticleEmitter); // We don't want to emit particles all the time, only when we hit something. if (hitParticles) hitParticles.emit = false; Patrol(); } function Patrol () { var curWayPoint = AutoWayPoint.FindClosest(transform.position); while (true) { var waypointPosition = curWayPoint.transform.position; // Are we close to a waypoint? -> pick the next one! if (Vector3.Distance(waypointPosition, transform.position) < pickNextWaypointDistance) curWayPoint = PickNextWaypoint (curWayPoint); // Attack the player and wait until // - player is killed // - player is out of sight if (CanSeeTarget ()) yield StartCoroutine("AttackPlayer"); // Move towards our target MoveTowards(waypointPosition); yield; } } function CanSeeTarget () : boolean { if (target == null) return; if (Vector3.Distance(transform.position, target.position) > attackRange) return false; var hit : RaycastHit; if (Physics.Linecast (transform.position, target.position, hit)) return hit.transform == target; return false; } function LateUpdate() { if (muzzleFlash) { // We shot this frame, enable the muzzle flash if (m_LastFrameShot == Time.frameCount) { muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward); muzzleFlash.enabled = true; if (GetComponent.<AudioSource>()) { if (!GetComponent.<AudioSource>().isPlaying) GetComponent.<AudioSource>().Play(); GetComponent.<AudioSource>().loop = true; } } else { // We didn't, disable the muzzle flash muzzleFlash.enabled = false; enabled = false; // Play sound if (GetComponent.<AudioSource>()) { GetComponent.<AudioSource>().loop = false; } } } } function Shoot () { var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit; // Did we hit anything? if (Physics.Raycast (transform.position, direction, hit, range)) { // Apply a force to the rigidbody we hit if (hit.rigidbody) hit.rigidbody.AddForceAtPosition(force * direction, hit.point); // Place the particle system for spawing out of place where we hit the surface! // And spawn a couple of particles if (hitParticles) { hitParticles.transform.position = hit.point; hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal); hitParticles.Emit(); } } // Start shoot animation GetComponent.<Animation>().CrossFade("shoot", 0.01); GetComponent.<AudioSource>().Play(); // Wait until half the animation has played //yield WaitForSeconds(delayShootTime); /* // Fire gun BroadcastMessage("Fire"); */ //target.SendMessage("Fire", SendMessageOptions.DontRequireReceiver); target.SendMessage("PlayerDamage", Damage, SendMessageOptions.DontRequireReceiver); // Wait for the rest of the animation to finish //yield WaitForSeconds(GetComponent.<Animation>()["shoot"].length - delayShootTime); // Register that we shot this frame, // so that the LateUpdate function enabled the muzzleflash renderer for one frame m_LastFrameShot = Time.frameCount; enabled = true; if (target == null) return; } function AttackPlayer () { var lastVisiblePlayerPosition = target.position; while (true) { if (CanSeeTarget ()) { // Target is dead - stop hunting if (target == null) return; // Target is too far away - give up var distance = Vector3.Distance(transform.position, target.position); if (distance > shootRange * 3) return; lastVisiblePlayerPosition = target.position; if (distance > dontComeCloserRange) MoveTowards (lastVisiblePlayerPosition); else RotateTowards(lastVisiblePlayerPosition); var forward = transform.TransformDirection(Vector3.forward); var targetDirection = lastVisiblePlayerPosition - transform.position; targetDirection.y = 0; var angle = Vector3.Angle(targetDirection, forward); // Start shooting if close and play is in sight if (distance < shootRange && angle < shootAngle) yield StartCoroutine("Shoot"); } else { yield StartCoroutine("SearchPlayer", lastVisiblePlayerPosition); // Player not visible anymore - stop attacking if (!CanSeeTarget ()) return; } yield; } } function SearchPlayer (position : Vector3) { // Run towards the player but after 3 seconds timeout and go back to Patroling var timeout = 3.0; while (timeout > 0.0) { MoveTowards(position); // We found the player if (CanSeeTarget ()) return; timeout -= Time.deltaTime; yield; } } function RotateTowards (position : Vector3) { SendMessage("SetSpeed", 0.0); var direction = position - transform.position; direction.y = 0; if (direction.magnitude < 0.1) return; // Rotate towards the target transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime); transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0); } function MoveTowards (position : Vector3) { var direction = position - transform.position; direction.y = 0; if (direction.magnitude < 0.5) { SendMessage("SetSpeed", 0.0); return; } // Rotate towards the target transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime); transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0); // Modify speed so we slow down when we are not facing the target var forward = transform.TransformDirection(Vector3.forward); var speedModifier = Vector3.Dot(forward, direction.normalized); speedModifier = Mathf.Clamp01(speedModifier); // Move the character direction = forward * speed * speedModifier; GetComponent (CharacterController).SimpleMove(direction); SendMessage("SetSpeed", speed * speedModifier, SendMessageOptions.DontRequireReceiver); } function PickNextWaypoint (currentWaypoint : AutoWayPoint) { // We want to find the waypoint where the character has to turn the least // The direction in which we are walking var forward = transform.TransformDirection(Vector3.forward); // The closer two vectors, the larger the dot product will be. var best = currentWaypoint; var bestDot = -10.0; for (var cur : AutoWayPoint in currentWaypoint.connected) { var direction = Vector3.Normalize(cur.transform.position - transform.position); var dot = Vector3.Dot(direction, forward); if (dot > bestDot && cur != currentWaypoint) { bestDot = dot; best = cur; } } return best; } and i have my agent to sooht ehen he spot the player and in range.. but how can i manage to make agent walk when use waypont and run towards the player when it spot the player? i tried with GetComponent.<Animation>().CrossFade("run", 0.3); GetComponent.<Animation>().CrossFade("walk", 0.3); and with SendMessage("SetSpeed", 4.0); lines of code but cannot managed to work animations names are simply walk, run, shoot any help is appreciated..
  14. Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/TargetScript.cs(500,65): error CS1061: Type `TacticalAI.HealthScript' does not contain a definition for `PlayerDamage' and no extension method `PlayerDamage' of type `TacticalAI.HealthScript' could be found (are you missing a using directive or an assembly reference?) what I missed?
  15. i was serching it too but as i know it doesnt work anymore on unity 5