Issues after "Fully Event Based Raycasting"

Hi!
After the Fully Event Based Raycasting lesson the game highlighted different errors then the ones in the video.

I tried to fix it myself but my programming skills are not the best, it might look a common mistake for you, I just cannot overcome it. Tried to continue the lecture, watch the next videos hoping that it will show me the way to fix it, but it did not work out.

Is there any option to copy the codes from somewhere at this point of the lecture to be able to continue the lessons?
Do you have any suggestions?

Thank you in advance!

Hi Tamás,

Looking at the errors that are listed I would say you have an issue with the placement of brackets/braces. If you copy/paste your PlayerMovement.cs script into a reply (and apply code formatting please) I will happily take a look for you.


See also;

1 Like

Hi Rob,

Thank you for helping me out with this. :slight_smile:

using System;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;

[RequireComponent(typeof (ThirdPersonCharacter))]
public class PlayerMovement : MonoBehaviour
{
    [SerializeField] float walkmovestopraidus = 0.2f;
    [SerializeField] float attackmovestopraidus = 0.7f;

    ThirdPersonCharacter ThirdPersonCharacter;   // A reference to the ThirdPersonCharacter on the object
    CameraRaycaster cameraRaycaster;
    Vector3 currentDestination, clickPoint;

        
    private void Start()
    {
        cameraRaycaster = Camera.main.GetComponent<CameraRaycaster>();
        ThirdPersonCharacter = GetComponent<ThirdPersonCharacter>();
        currentDestination = transform.position;
    }

    // Fixed update is called in sync with physics
    private void FixedUpdate()
    {
        Processmousemovement();

    }

    private void Processmousemovement()
    {
    //    if (Input.GetMouseButton(0))
    //    {
    //        clickPoint = cameraRaycaster.hit.point;
    //       switch (cameraRaycaster.CurrentLayerHit)
    //        {
    //            case Layer.Walkable:
    //                currentDestination = ShortDestination(clickPoint, walkmovestopraidus);
    //                break;
    //            case Layer.Enemy:
    //                currentDestination = ShortDestination(clickPoint, attackmovestopraidus);
    //                break;
    //            default:
    //                print("should not be here");
    //                return;
    //        }
    //    }
    //    WalktoDestination();
    //}

    private void WalktoDestination()
    {
        var PlayerToClickPoint = currentDestination - transform.position;
        if (PlayerToClickPoint.magnitude >= 0)
        {
            ThirdPersonCharacter.Move(PlayerToClickPoint, false, false);
        }
        else
        {
            ThirdPersonCharacter.Move(Vector3.zero, false, false);
        }
    }

    private Vector3 ShortDestination(Vector3 destination, float shortening)
    {
        Vector3 reductionVector = (destination - transform.position).normalized * shortening;
        return destination - reductionVector;
    }
    void OnDrawGizmos()
    {
        Gizmos.color = Color.black;
        Gizmos.DrawLine(transform.position, currentDestination);
        Gizmos.DrawSphere(currentDestination, 0.1f);
        Gizmos.DrawSphere(clickPoint, 0.15f);
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, attackmovestopraidus);

    }
}
1 Like

Hi,

If you have a look at your method Processmousemovement, where you’ve commented out the code, you have also commented out the closing brace }.

Because of this, the compiler is unable to make sense of the code which follows. Your errors have then cascaded.

Uncomment the closing brace and you should find those errors disappear.

Hope this helps :slight_smile:

1 Like

I fixed the bracket issue, but after that I got even more errors about a whole bunch of other stuff. :frowning:

324

At a glance of the limited information I can actual view it looks like you may have more than one class with the same name.

Could you share your project files with me please. If you project is 10mb or less you can just zip it up and upload it into a reply. If it is larger than 10mb you can use a service such as Google Drive or Dropbox and then just put the URL to the zip file in your reply.

I will take a look but it may not be this evening due to time constraints.

1 Like

Well, it is a little more than 10mb. :smiley:
I was not sure which files do you need exactly so I wrapped the whole project.
https://drive.google.com/open?id=1zVFSSy3d0tx2Je_QetsnOKQK5PCaLuVc

Hi Tamas,

Your issue appears to be one of housekeeping :slight_smile:

The first error in the list is caused by you having a class with the same name in the same namespace. Global is effectively not in a specific namespace. I opened your project within Visual Studio and, as you are using the Standard Assets you have multiple projects (that’s ok). But the problem is that you have, by the looks of it, copied a folder from your project directly into the Editor directory, thus creating a copy of the same named class.

Here’s a screen shot to show you;

image

The above is your main project. The three projects below the red box are those required in order for their classes to be built so that you can then use them within Unity.

If we however expand the Tutorial_rpg.Editor project (the second project in this list), we can see this;

The green box identifies the second project, the red box within it identifies a duplication from your main project that has been added to this one.

Visual Studio is creating errors because of these duplicates.

If you apply a little housekeeping and tidy up, you should be able to remove these errors.

Hint : Remove the entire folder, “Assets”, as shown in the red box within the green box in the above screenshot, everything in it etc… all errors are removed.

Note: The above step assumes you haven’t been working on/modifying these duplicates scripts by mistake. If you have any doubt, make a backup of your work first (outside of the project).

After this, when you run the game (Village scene) you’ll have a couple of other errors spring up.

The first is that your Main Camera is now missing a script, this is because you had referenced one of the duplicated ones instead of the one in your main project. Following the error message through I believe this should be the CameraRaycaster.cs script. You will then need to specify the size of the layers array and select the layers accordingly.

The next issue is that this scene is missing an Event System, this isn’t related to the duplication of files, you’re just missing one. Right-click in the Hierarchy and select UI / Event System.

After this you should be able to run the game again (Village scene) and move the mouse around and the cursor will change accordingly to target, walk, unknown etc.

If you click to walk you will receive another error message, this time because your notifyMouseClickObservers is null - I’ll let you have a look at that one. :slight_smile:

Hope this helps you get back to where you want/need to be.

1 Like

Hi Rob,

First of all, thank you for everything I really appreciate it!
After I got rid of the “Assests” the game worked again properly. I can continue to work on the project thanks to you. :slight_smile:
I feel ashamed of this mistake and I`ll try to be more careful in the future.

It`s nice to have people here who are actually help us.
Thank you once again!

1 Like

Hi Tamas,

You are more than welcome and I’m glad you can move forward again.

I suspect it was just an accident at one point, with a folder getting dragged into another by accident. It has however made you aware of name clashes when there are classes within the same namespace sharing the same names, even if they are in different folders, so I would say that has been useful, even if a little frustrating for you. :slight_smile:

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

Privacy & Terms