CameraRaycaster script - don't see the layers

Be sure its

using UnityEngine;

as you will find there is already a;

using UnityEditor;

They look quite similar, and the Debug class belongs to UnityEngine :slight_smile:

Yep - you misread :slight_smile:

You should have two directives at the top of that script;

using UnityEditor;
using UnityEngine;

give that a go :slight_smile:

My bad.

Now it’s good:
OnInspectorGUI was called
UnityEngine.Debug:Log(Object)
CameraRaycasterEditor:OnInspectorGUI() (at Assets/Editor/CameraRaycasterEditor.cs:13)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

No worries, I made the same mistake myself initially :slight_smile:

Ok, so we know the Editor script is being called, you can take those changes back out now.

There are two noticeable differences between the code I have here, and that which you posted earlier.

I have the code within namespaces, but that may come in a later lecture, I can’t recall and the other is that in CameraRaycaster.cs I have the layerPriorities initialised to null at the top of the script, e.g.

public class CameraRaycaster : MonoBehaviour
{
	// INSPECTOR PROPERTIES RENDERED BY CUSTOM EDITOR SCRIPT
	[SerializeField] int[] layerPriorities = null;

        // ....

I don’t expect this will make a difference, but wouldn’t hurt to try it out.

Having explored a few of the easier things to test, my next suggestion would be to zip up your project files and share them with me here and I’ll open your project and have a look around, if you are happy for me to do so.

The forum allows files up to 10mb, I suspect the RPG course project will be much larger than that, as such, you’ll need to use a service such as Google Drive or Dropbox and share the URL with me. Please zip the entire project files, as opposed to doing a package extraction.

Happy to take a look :slight_smile:

OK. It will take a few minutes.
I’ll share the link here.

1 Like

No worries, whatever it ends up being will be one of those “Oh really!!” kind of moments I suspect, something really small/silly that neither of us have spotted…hehe… :slight_smile:

As experiance showed before … it will be small/capital letter ):

1 Like

Try this link

https://lbcadcare-my.sharepoint.com/:u:/p/lior-b/EZ8u9G7sanFNsA7_9V5Xd7ABKzsqfsriCOhJUmrhmxLuoQ?e=hf928b

Grabbing it now… will need a little bit of time to look through now, might not reply for a little while…

I’m patiant. Take your time.
Most important… THANK YOU FOR HELPING

2 Likes

Just opened your project.

Your Size for the Layer Priorities is set to 0, e.g. the size of the array;
image

This indicates an empty array.

As soon as I changed this to 2 (or indeed any number), the CameraRaycasterEditor.cs script did exactly what it was supposed to;
image

…and from there, I can change the layer from Default to Enemy or Walkable for example;
image

Sorted :slight_smile:

image


Couple of additional points…

In that last screenshot I had Walkable above Enemies in the layer priority, you will want them around the other way;
image

Your enemies have a NavMeshAgent component on them, but the radius of Obstacle Avoidance is set to 10, due to their positioning, they are effectively have obstacles within that distance when the game starts, this is why they seeming all fly off and hide under houses at the start. They are being moved based on the value of this setting.

I change this to a value of 1 and the results were a little more desired, but obviously this is entirely up to you :slight_smile:

Finally, I noticed that you have the Auto Generate option turned on for your lighting, if you have a good spec PC/laptop etc this may not be an issue for you. I don’t, so I tend to find with it on Unity slows down quite a bit as it continually rebakes all the lighting as I move things around, you can see this in the bottom right-hand corner of Unity when it’s working;
image

If this is a problem for you also, you can disable it under Windows / Rendering / Lighting Settings;
image

…and then un-tick;
image

If you want to update the lighting later, after things have been moved around in the scene, just come back into this window and click the Generate Lighting button, or, re-enable Auto Generate etc.

2 Likes

As you said silly/small thing, how didn’t i noticed it??? well

How about the enemies are on their knees/bent, how can I fix that?

OK, after checking the cursor doesn’t change to targetCursor

How about the enemies are on their knees/bent, how can I fix that?

This is because models Animator believes it to be in a state of falling. Have a search on the forum, as this has been covered quite a lot in the past. Different people have resolved it (term used loosely) in different ways, many believing it to be just the ground distance check value, but it’s actually a bit more involved than that. There is, in fact, a ray being cast out of the bottom of the model and it’s effectively too short, but it needs to be placed further inside the model, e.g. upwards from memory. If you only change the ground check distance then as soon as you go over uneven ground the same issue occurs again.

One of many previous topics on the issue

OK, after checking the cursor doesn’t change to targetCursor

targetCursor being the sword? When I ran it I had the arrow for the movement, a question mark for unknown things and a sword for enemies.

Yes. the sword is targetCursor.
At runtime when pointing on enemy the cursor does not change. It does change for walkable and unknown.

Did you change the priority order in the layer priorities?

No.
How do i do that, if it’s in the lecture I’ll go find it.

It’s covered in my lengthy reply above, albeit many not the “how”… see the screenshots… e.g.

image

So, click on Walkable (you’ll note the two little arrows to the right of it) and then the layer selection appears, put enemies at the top, and walkable at the bottom.

OK. Changing the order solved the problem.
Yehhhh…

Rob, you where much help.
Thank you again.

2 Likes

You’re very welcome. We’ll mark this one as resolved now :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms