Search Unity

Realistic FPS Prefab [RELEASED]

Discussion in 'Assets and Asset Store' started by Azuline-Studios, Apr 5, 2013.

  1. Michealunity

    Michealunity

    Joined:
    Mar 15, 2015
    Posts:
    65
    hi i'm interesting to bought this but i need to know if animation are based only for arms or for total body mesh.
    Thanks
     
  2. polash

    polash

    Joined:
    Jul 8, 2015
    Posts:
    46
    Hello .
    Getting error on unity 5.6 "In order to call GetTransformInfoExpectUpToDate, RendererUpdateManager.UpdateAll must be called first."
     
  3. Arealjighead

    Arealjighead

    Joined:
    Apr 7, 2017
    Posts:
    32
    @Michealunity yes the player has full body animations
    @polash Azuline discussed this on the previous page. "Version 1.26 of the Realistic FPS Prefab is available for download now, which fixes a few things and upgrades the navmesh agent calls for Unity 5.6. The GetTransformInfoExpectUpToDate console error should be resolved soon in a future Unity release. Thanks for your patience."
     
  4. Deki3d-Virus

    Deki3d-Virus

    Joined:
    Dec 11, 2012
    Posts:
    23
    How to Raycast blood Decal on the wall when AI is Dead?
     
  5. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    164



    i tried the pause menu thing again :/ i dunno how to do it like that as it keeps coming up with this error:

    Assets/Resources/Scripts/PauseMenu.cs(28,21): error CS0029: Cannot implicitly convert type `bool' to `float'

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PauseMenu : MonoBehaviour {
    6.  
    7.  
    8.     public string levelSelect;
    9.  
    10.     public string titleScreen;
    11.  
    12.     private bool isPaused;
    13.  
    14.     public GameObject pausemenuCanvas;
    15.  
    16.  
    17.  
    18.     // Update is called once per frame
    19.     void Update () {
    20.         if (isPaused)
    21.         {
    22.             pausemenuCanvas.SetActive (true);
    23.             Time.timeScale = 0f;
    24.         }
    25.         else
    26.         {
    27.             pausemenuCanvas.SetActive (false);
    28.             Time.timeScale = isPaused;
    29.         }
    30.  
    31.         if(Input.GetKeyDown(KeyCode.Escape))
    32.             {
    33.             isPaused = !isPaused;
    34.             }    
    35.     }
    36.  
    37.     public void Resume()
    38.     {
    39.         isPaused = false;
    40.     }
    41.  
    42.     public void MapSelector()
    43.     {
    44.         Application.LoadLevel (2);
    45.     }
    46.     public void Restart()
    47.     {
    48.         Application.LoadLevel (Application.loadedLevel);
    49.     }
    50.     public void Options()
    51.     {
    52.        
    53.     }
    54.  
    55.     public void MainMenu()
    56.     {
    57.         Application.LoadLevel (0);
    58.     }
    59.     public void Quit()
    60.     {
    61.         Application.Quit();
    62.     }
    63. }
    64.  
     
  6. muhammadadnan0075

    muhammadadnan0075

    Joined:
    Dec 17, 2016
    Posts:
    14
    On Line 28 set Time.timeScale = 1.0f;
     
  7. Takahama

    Takahama

    Joined:
    Feb 18, 2014
    Posts:
    164
    @Azuline-Studios Major game breaking bug!
    in third person mode i got physic based projectile with some Hit Check Distance and while facing at enemy's direction but shooting down to ground makes projectile instantly hits NPC front of me! i think it happens because spawn position of projectile faces forward for a milisecond.
    Also please add an bolt action sniper rifle with camera setup for scope for showing correct way to do physics based bullet system.
     
  8. AresTheDog

    AresTheDog

    Joined:
    Dec 26, 2016
    Posts:
    3
    So checking out the lastest v1.27 with Unity 5.6.0f3 and it seems wacky. When you jump/move the gun bobs up and down like its a bobble head on springs.

    Other two errors:

    Use of UNITY_MATRIX_MV is detected. To transform a vertex into view space, consider using UnityObjectToViewPos for better performance.
    (Assets/RFPSP/Demo/Other/Terrain Assets/Trees Ambient-Occlusion/Billboard.shader)

    File 'Idle' has animation import warnings. See Import Messages in Animation Import Settings for more details

    Is there a particular unity version that works best for this kit?
     
  9. KrytalityStudios

    KrytalityStudios

    Joined:
    Sep 12, 2016
    Posts:
    22
    Hi. I'm have an issue where in the scenes that don't have a player in the scene, particle systems wont play, animations wont play, and probably other issues I haven't encountered yet.

    Please fix this bug as it is hindering me from adding particle effects and animations to my main menu.

    I have been an RFPS customer for about half a year and I love your asset. Thank you for the recent updates and all the hard work you have put into this product. I greatly appreciate it.
     
  10. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    This is the same issue I recently had. Go into Time settings and set your Time Scale to 1.0.
     
  11. muhammadadnan0075

    muhammadadnan0075

    Joined:
    Dec 17, 2016
    Posts:
    14
    Haven't checked 1.27 but It looks like the Billboard shader isn't compiling with unity 5.6.0f3. Try switching Billboard.shader to some transparent shader.
    The idle animation warning doesn't affect the package as they sometime are incorrect behavior of unity.
     
  12. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    164
    i did that but it affects bullet time... is their any other way of setting the timescale to 1 without doing that?
     
  13. AresTheDog

    AresTheDog

    Joined:
    Dec 26, 2016
    Posts:
    3
    Thank you for your advice. That was exactly what was happening. I re-opened it this morning and it recompiled on it's own and errors gone. Plus it now runs smooth without any problems visually.

    However, I get this as you play through. Research says it's a known issue but cannot pinpoint where it comes from.

    Error:
    Code (csharp):
    1. In order to call GetTransformInfoExpectUpToDate, RendererUpdateManager.UpdateAll must be called first.
    So this asset is broken with Unity 5.6.03f1. Appears to be a unity issue.

    So I downgraded to 5.5.3f1. Now a different problem. Framerate is super low, extemely laggy game play. Reloading and recompiling does not fix this.

    Error: Occlusion culling data is out of date. Please rebake

    So this asset is broken with Unity 5.5.3f1 and this is apparently fixed by adding a material to the occluder mesh but I didn't find the source anywhere.

    So enough hours wasted on a broken asset and broken unitys.

    Can anyone suggest what Unity version runs this asset correctly?
     
    Last edited: Apr 29, 2017
  14. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    I did this and it works fine for walking up and down stairs, but it no longer plays footsteps sounds when going up/down these invisible ramps. Any idea how to fix that?
     
  15. Arealjighead

    Arealjighead

    Joined:
    Apr 7, 2017
    Posts:
    32
    @magique Change the Tag of the box collider to Wood,Metal, or Stone.
     
  16. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    Thanks. It worked.
     
  17. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    243
    I'm on Unity 5.4.3f and RSPF 1.24 and it works great. Occasionally get an unity corruption but it has been Very stable for me in this config and I'm not looking to upgrade anytime soon because of it.
     
  18. yedpodtrzitko

    yedpodtrzitko

    Joined:
    Aug 22, 2014
    Posts:
    2
    Hi,
    thanks for the great asset.

    Sorry if my following question has been answered already, I just want to avoid reinventing wheel.

    I'd like to implement RTS-like camera which would be activated and moved around (without moving the actual player's avatar). Is that somehow possible? Just deactivating the FPS camera & activating different one gives me error, because `GunSway.Update()` tries to manipulate the FPS camera.

    Thanks for any hint.
     
  19. o0neza0o

    o0neza0o

    Joined:
    Sep 6, 2015
    Posts:
    164
    is tactical ai a good plugin for rfps?
     
  20. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    243
    Optimization: Bloom, Sunshafts, Colour Correction still active.
    Config: Unity v5.4.03f and RSFP v1.24

    Hi all, I have a question for the group about how some of the scripts on the player prefab are running.

    I am trying to optimize RFPS for the fastest possible play on mobile. Right now I have it running at 90-100 fps on an S7 in VR with full 3d levels and monsters and weapons scripts running and such.

    I am happy with that rate, but I noticed in the profiler that Sunshaft, Bloom optimized and Color Correction scripts are still running, even though I have turned them "OFF" in the Inspector menu (both main camera and weapon camera) AND THEY ARE TAKING UP 12% of total CPU resources!!!!!!!
    sun_shaft.jpg

    Does anyone know if some script somewhere calls these dynamically or why these would still even be active? I've tried chasing it down but with no luck. I tried deleting these scripts entirely, but then the player prefab throws an error which means some script somewhere must be looking for them.

    I'd rather have that CPU resource go towards antiasiling or adding a few more monsters or maybe a trap or something other then running these scripts, since CPU cycles are precious on mobile.

    Thanks all.
     
  21. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    243
    Optimization: Bloom, Sunshafts, Colour Correction still active.
    Config: Unity v5.4.03f and RSFP v1.24

    Hi all, I have a question for the group about how some of the scripts on the player prefab are running.

    I am trying to optimize RFPS for the fastest possible play on mobile. Right now I have it running at 90-100 fps on an S7 in VR with full 3d levels and monsters and weapons scripts running and such.

    I am happy with that rate, but I noticed in the profiler that Sunshaft, Bloom optimized and Color Correction scripts are still running, even though I have turned them "OFF" in the Inspector menu (both main camera and weapon camera) AND THEY ARE TAKING UP 12% of total CPU resources!!!!!!!
    View attachment 229178

    Does anyone know if some script somewhere calls these dynamically or why these would still even be active? I've tried chasing it down but with no luck. I tried deleting these scripts entirely, but then the player prefab throws an error which means some script somewhere must be looking for them.

    I'd rather have that CPU resource go towards antiasiling or adding a few more monsters or maybe a trap or something other then running these scripts, since CPU cycles are precious on mobile.

    Thanks all.
     
    Weblox likes this.
  22. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    I have mine all turned off in the inspector and they stay turned off so I don't know why that doesn't work for you. But I'm with you on this though. Those scripts should not be on there to begin with and the code shouldn't expect them. Post effects is not the domain of this asset and they should be removed.
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    What's the proper way to disable the FPS player so that its essentially turned off? I have a part where I need to pause the player and have an overlay render on top of the scene with a talking character. The entire scene is essentially still active, but I want the player unable to do anything. I have some code to disable various RFPS components, which took a while to figure out which ones and in what order without getting exceptions. However, if the player is looking around when I run this code, the camera continues to spin around the room while the player is "paused." I figure there must be a proper way to handle this without all the hoops I'm trying to jump through.
     
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    The Asset Store delivers different versions of the RFPS package for Unity 5.6 and for Unity 5.2.5 - 5.5. If you created your project in Unity 5.6 and downloaded and imported RFPS, your project contains the Unity 5.6 version. To downgrade to a lower version of Unity, delete your RFPSP folder, and then redownload and reimport from the Asset Store.

    Find the MovePlayerAndCamera component on the FPS Camera GameObject. Enable it. Edit the script and comment out the entire Update() method, which was left in there for testing.

    When you want to pause the player, find this script and call its ReleaseMainCameraAndMovePlayer() method. This method toggles RFPS's control off and on. So when you want to unpause the player, call the method again.
     
    Hormic likes this.
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    This doesn't quite work. It wants me to assign a Cinema Camera and assumes I'm switching to this camera. I think I can put together another similar function though based on the ReleaseMainCameraAndMovePlayer() function that doesn't do all the cinema camera stuff.

    [EDIT]
    Got it working by making a new function called TogglePlayerControl() and it's essentially the same as the ReleaseMainCameraAndMovePlayer() function without the camera switch and player move portion.
     
    Last edited: May 2, 2017
    TonyLi likes this.
  26. rbm123

    rbm123

    Joined:
    May 24, 2015
    Posts:
    125
    Hi
    I have updated unity from 5.3.3 to 5.6.0f3 and now I have this error:

    Assets/RFPSP/Scripts/AI/AI.cs(964,8): error CS1622: Cannot return a value from iterators. Use the yield return statement to return a value, or yield break to end the iteration

    what should I do?
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    What version of RFPSP are you using? I checked my own script at that line and there's no return there at all. And I couldn't find any invalid return statement in that entire function.
     
  28. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    Make a backup of your project first, just in case. Open the Asset Store window. Go to your downloads (the square with the down arrow). Find Realistic FPS Prefab, and click Download. This will download the latest RFPS for Unity 5.6. Then import it. It'll fix those errors.
     
  29. rbm123

    rbm123

    Joined:
    May 24, 2015
    Posts:
    125
    I'm Using RFPS 1.23

    I'm From Iran and I don't have access to your payment services!
    I asked one of my customers (I'm web designer) from America to buy RFPS from assets store a few months ago And Also he Didn't Gives me the invoice number!So I don't know he had really buy it or its a pirate download! Does not answer his e-mails !!
    So can you help me to change the codes?
     
  30. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    You could check with Azuline Studios to see if they have another way to buy and download RFPS.
     
  31. rbm123

    rbm123

    Joined:
    May 24, 2015
    Posts:
    125
    which RFPS version works with unity 5.6.0f3 ?
     
  32. Dumad123

    Dumad123

    Joined:
    Aug 22, 2013
    Posts:
    15
    Hello. I am trying to create a time traveling mechanic. I currently have it so that when i press a button, it disables a game object (I have all of the enemies parented underneath the game object). However, when I disable, then re-enable the ai , the ai stand still, and do not attack the player. Is there another method to temporary "disable" them when i press a button, then to unpause when i press the button again and have the ai still work?

    I currently use this script
    Code (JavaScript):
    1. #pragma strict
    2. var Past : GameObject;
    3. var Present : GameObject;
    4. var On : boolean;
    5. function Update () {
    6.      if (Input.GetKeyDown(KeyCode.O)) {
    7.          if (On == true) {
    8.              On = false;
    9.          } else {
    10.              On = true;
    11.          }
    12.      }
    13.    
    14.      if (On == true) {
    15.      Past.SetActive(true);
    16.      Present.SetActive(false);
    17.      } else {
    18.      Past.SetActive(false);
    19.      Present.SetActive(true);  
    20.      }
    21. }
    and the editor hierarchy looks like this

    Past
    >Bad guy
    >Light

    Present
    >Light2

    So when I press the button, it disables the past game object and everything underneath it. Then, it re-enables. The enemy ai however from the kit when re-enabled stands still and does not do anything.

    Thanks
     
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    Call the AI component's SpawnNPC() method to restart its coroutine.
     
  34. Dumad123

    Dumad123

    Joined:
    Aug 22, 2013
    Posts:
    15
    Could you elaborate and expand on what you mean there - and how you can do that? I am new to coding so I apologize for being slightly clueless
     
  35. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    Try adding this line:
    Code (csharp):
    1. Past.SetActive(true);
    2. Past.GetComponent<AI>().SpawnNPC(); // ADD THIS LINE.
     
  36. Dumad123

    Dumad123

    Joined:
    Aug 22, 2013
    Posts:
    15
    Do I insert anything inside the parentheses? Is this where I restart the coroutine?
    Because currently, if I add in the line, it comes up with these errors:
    Assets/RFPSP/Scripts/Time Travel/TimeTravel.js(16,28): BCE0043: Unexpected token: ).
    Assets/RFPSP/Scripts/Time Travel/TimeTravel.js(16,29): BCE0044: expecting ), found '.'.
    Assets/RFPSP/Scripts/Time Travel/TimeTravel.js(16,30): UCE0001: ';' expected. Insert a semicolon at the end.


    Edit: Is it because the code I have is in Java, and the snippet you gave me is in C#?
     
    Last edited: May 4, 2017
  37. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    @Dumad123, You might want to update your scripts to C# because Unity is going to be
    You're using Javascript so the code would look like this, I believe:

    Code (JavaScript):
    1. var ai: AI = Past.GetComponent(AI) as AI;
    2.         if (ai != null)
    3.             ai.SpawnNPC();
    [EDIT]
    However, I would highly recommend you move to C#. JS is dying in Unity.
     
    TonyLi likes this.
  38. Dumad123

    Dumad123

    Joined:
    Aug 22, 2013
    Posts:
    15

    So I edited my script to c#, and tried again with the added snippet @TonyLi gave me, however, I still have the issue where the AI stands still, and does nothing. I am using this code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TimeTravel : MonoBehaviour {
    5.  
    6.     public GameObject Past;
    7.     public GameObject Present;
    8.     public bool  On = false;
    9.     void  Update (){
    10.         if (Input.GetKeyDown(KeyCode.O)) {
    11.             if (On == true) {
    12.                 On = false;
    13.             } else {
    14.                 On = true;
    15.             }
    16.         }
    17.  
    18.         if (On == true) {
    19.             Past.SetActive(false);
    20.             Present.SetActive(true);
    21.         } else {
    22.             Past.SetActive(true);
    23.             Past.GetComponent<AI>().SpawnNPC();
    24.             Present.SetActive(false);
    25.         }
    26.     }
    27. }
    But I now I get this error
    My current hierarchy looks like this
     
  39. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    You probably forgot to assign the Past and Present objects from the scene hierarchy. Check your inspector.
     
  40. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    @Dumad123 - Since the Past GameObject doesn't have the AI component, instead of this:
    Code (csharp):
    1. Past.GetComponent<AI>().SpawnNPC();
    try this:
    Code (csharp):
    1. foreach (var ai in Past.GetComponentsInChildren<AI>()) {
    2.     ai.SpawnNPC();
    3. }
    This will reactivate the AI components in all of the child GameObjects.
     
    Weblox likes this.
  41. Dumad123

    Dumad123

    Joined:
    Aug 22, 2013
    Posts:
    15
    @TonyLi Where would I place that code snippet? I currently have it here, and it still has the same issue. (snippet was placed is at line 23)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TimeTravel : MonoBehaviour {
    5.  
    6.     public GameObject Past;
    7.     public GameObject Present;
    8.     public bool  On = false;
    9.     void  Update (){
    10.         if (Input.GetKeyDown(KeyCode.O)) {
    11.             if (On == true) {
    12.                 On = false;
    13.             } else {
    14.                 On = true;
    15.             }
    16.         }
    17.  
    18.         if (On == true) {
    19.             Past.SetActive(false);
    20.             Present.SetActive(true);
    21.         } else {
    22.             Past.SetActive(true);
    23.             foreach (var ai in Past.GetComponentsInChildren<AI>()) {
    24.                 ai.SpawnNPC();
    25.             }
    26.             Present.SetActive(false);
    27.         }
    28.     }
    29. }
     
    Last edited: May 5, 2017
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,766
    I have a feature request. It would be nice to be able to have the player knock back or knockdown on big hits. So if I'm battling a tough monster and take a massive blow then I might get knocked back and staggered or even knocked back and down on the ground. This could cause the player to be unable to respond for a second or two while he gets back up. There could be various variables involved to determine if and when these events could occur and so forth. Some of this could also apply to the enemy AI as well so they could be knocked back by a big blow. But I'm most interested in player behavior for this since I'm not using the built-in AI anyway.
     
  43. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    256
    This is again some helpful information. I will save out this script, just in case I might need it later. However I would like to ask a follow up Question at this Point:

    @TonyLi When I set up my Game Levels I always try to work with AI Spawners that will respawn NPCs and reset Events after a certain amount of time. As a result I have most of my active NPCs spawned into the Game Level at runtime, appearing unparented in the Hierarchy (mostly with the (Clone) extension). Is there a way to find all those active NPCs in my Level via script also, and disable/re-enable them at runtime (e.g when turning off the Player Controller and switch to control a Vehicle/Boat/Plane...) ? As always, thanks in advance... ;)
     
    Last edited: May 5, 2017
  44. rbm123

    rbm123

    Joined:
    May 24, 2015
    Posts:
    125
    I cant Upgrade to newer version
    So which codes need to be change to fix this problem?
    (sorry for my English)
     
  45. jadorks

    jadorks

    Joined:
    Jul 11, 2016
    Posts:
    10
    Hello.
    Um, I was wondering if I could make a system where the A.I would wait for some seconds before attacking the player. It's kind of a reaction cowboy shootout game and I want to say Ready, Steady and at a random time bang, then after some microseconds the A.I attacks the player. Also I want the player to miss if the player shoots before bang.
     
  46. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    243
    Hey! Question for Tony Li and his save system for RSPF
    Unity 5.4.03f and RSPF 1.24 , win 8.1 and building for android.

    So, a few weeks ago I got the prefab and gave it a quick try and it seemed to work great, then set it aside and worked on other aspects of my game Now I am back working with the prefab and have hit a few snags that I can't figure out.

    When I set up portal scene changes with the portal prefab none of my inventory from scene one, transfers to scene two. (although the portal works great for bouncing between the scenes)
    Then, when I set up my game object as the spawn point. The RSP player does not spawn in that location, but in the location that I have the RSPF prefab in the scene.

    So I'm missing something somewhere (it's almost like the data is not getting saved and I wonder if I have a drive read/write lock on or something)

    So a question. Do I have to have to have all the pickups that are in my inventory already in both scenes? (example: If I have the sword pickup prefab in scene one. Do I actually have to have the physical model loaded somewhere in scene two to have the inventory access it?) Or will it just come through on the inventory from scene one?

    I noticed that If I don't have the player prefab in scene two already, then the transition from scene one doesn't happen. The error is something like: Does not have an active camera in scene two.
    So does that mean I have ot have the player prefab loaded somewhere in scene two

    I also noticed that when I add the save code into menu.cs. It seems to save fine, but when I hit load, the game does not load from the last saved location but rather from where the RFPS refab is located. (hence my thought on the read/write lock.)

    Anyway, I know it all worked once a few weeks back and I have tried two different test projects now, where it doesn't work and I'm at a bit of a lose as to why it's not working now.....
     
  47. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    Hi @jons190 - You must have a player prefab in both scenes, and you must add an FPS Player Saver component to them as described on page 6 of the manual. Take a look at the Save System for RFPSP's demo scenes for an example. Once that's configured the player should appear where it's supposed to.

    The pickups don't need to be in both scenes. But they should be configured with a Destructible Saver as described on page 7.

    If you want to keep track of objects the player has dropped (so Unity can respawn them when you reenter the scene), you'll want to add a Spawned Object Manager as described on page 9.

    If you get stuck on any of this, let me know here or via PM, or email me directly at tony (at) pixelcrushers.com, whatever you prefer.
     
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,083
    Hi @Weblox - In script, you should be able to find them like this:
    Code (csharp):
    1. AI[] npcs = FindObjectsOfType<AI>(); // Get all AI components on active GameObjects.
    You could write a method to toggle these on and off, passing the npcs array you got from the code above:
    Code (csharp):
    1. void SetNPCs(AI[] npcs, bool value) {
    2.     foreach (var npc in npcs) {
    3.         npc.enabled = value;
    4.     }
    5. }
     
    Weblox likes this.
  49. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    243

    Hey Thanks Tony! I got this all to work. The old "put the saver script on BOTH prefabs" was what was tripping me up. Somehow I missed that step. Still couldn't get the inventory to track through.

    Sometimes I seem to pick up an odd error like this that I can never seem to purge in my unity projects. I think it's unity thing. But I set up a new project with all the plugings I use (rfps saver and rewired) and now just got everything to work great! Whew! I'm going to start using this as the base of my projects.... a project "prefab" if you will........... Now, I need to tackle "dead zone aiming" for the VR. It currently doesn't work out of box and I can't get good ingame vision tracking/aiming with the bow. Where you point, is not where it shoots! Anyway, onward off to learn all I can now about VECTOR2.move code!!!!!!
     
    TonyLi likes this.
  50. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    256

    Hi @TonyLi - Thanks a lot for your constant help and support. :) :) :)

    I have tried to use the code "as it is" and fire up the "SetNPCs" function with the Unity.Events (in my quick setup with OnEnter() a trigger zone).

    I had to move the first line into void start () because Unity gave an Error.

    FindObjectsOfType is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'AI_ToggleActive' on game object 'AreaLimits'. See "Script Serialization" page in the Unity Manual for further details.UnityEngine.Object:FindObjectsOfType() AI_ToggleActive:.ctor() (at Assets/RFPSPAssets/Scripts/AI_ToggleActive.cs:9

    I had expected to find the "SetNPCs" - Function in the dropout section of the Unity.Events System, but oddly it does not appear there. I have tried to set it to "public void" also, with the same result. This is how I tried to use the Script :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AI_ToggleActive : MonoBehaviour
    6. {
    7.  
    8.     // Use this for initialization
    9.     void Start()
    10.     {
    11.         AI[] npcs = FindObjectsOfType<AI>(); // Get all AI components on active GameObjects.
    12.     }
    13.  
    14.    void SetNPCs(AI[] npcs, bool value)  // Toggle NPCS Active or not
    15.     {
    16.         foreach (var npc in npcs)
    17.         {
    18.             npc.enabled = value;
    19.         }
    20.     }
    21. }
    22.  

    Maybe this is because the SetNPCs() values have been declared in Line 14 ? Or did I miss something else ? As always any help is much appreciated and thanks for all your effort. ;)
     
    Last edited: May 7, 2017
unityunity