I don't know if this is working properly

So this works perfectly on the first map i created, which is a town map, im slowly but surely constructing, which is where i made this changes, but when i go to my proper level, while everything triggers, the circle doesn’t appear and i can’t manage to make it appear on the ground. I will share my code of DelayClickTargeting, to see if anyone see’s an error there. But other then that, i have not touch anything from the OG prefab.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Control;
using UnityEditor;

namespace RPG.Abilities.Targeting{

    [CreateAssetMenu(fileName = "Delay Click Targeting", menuName = ("RPG/Ability/Targeting/Delay Click"), order = 0)]
    public class DelayClickTargeting : TargetingStrategy{
        // Config Data
        [SerializeField] Texture2D cursorTexture;
        [SerializeField] Vector2 cursorHotspot;
        [SerializeField] int areaEffectRadius;
        [SerializeField] LayerMask layerMask;
        [SerializeField] Transform targetingPrefab;

        // State
        Transform targetingPrefabInstance = null;

        public override void StartTargeting(GameObject user,
            Action<IEnumerable<GameObject>> finished){

            PlayerController playerController = user.GetComponent<PlayerController>();
            playerController.StartCoroutine(Targeting(user, playerController, finished));
        }

        private IEnumerator Targeting(GameObject user,
            PlayerController playerController,
            Action<IEnumerable<GameObject>> finished){

            playerController.enabled = false;

            if(targetingPrefabInstance == null)
                targetingPrefabInstance = Instantiate(targetingPrefab);
            else targetingPrefabInstance.gameObject.SetActive(true);

            targetingPrefabInstance.localScale = new Vector3(areaEffectRadius * 2, 1,
                areaEffectRadius * 2);

            while(true){

                Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.Auto);
                RaycastHit rayCastHit;

                if(Physics.Raycast(PlayerController.GetMouseRay(),
                    out rayCastHit, 1000, layerMask)){

                    targetingPrefabInstance.position = rayCastHit.point;

                    if(Input.GetMouseButtonUp(0)){
                        yield return new WaitWhile(() => Input.GetMouseButton(0));
                        
                        playerController.enabled = true;
                        
                        finished(GetGameObjectsInRadius(rayCastHit.point));

                        targetingPrefabInstance.gameObject.SetActive(false);

                        yield break;
                    }
                }
                yield return null;
            }
        }

        private IEnumerable<GameObject> GetGameObjectsInRadius(Vector3 point){
            RaycastHit[] hits = Physics.SphereCastAll(point, areaEffectRadius,
                Vector3.up, 0);
            
            foreach(RaycastHit hit in hits)
                    yield return hit.collider.gameObject;
        }
    }
}

Check to see if you set up the layer for the terrain. I made that mistake a few days ago.

1 Like

I will do right now

Yep, it was just that, completely forgot the kind of Layer this needed, thanks @edc237 :smiley:

Glad I could help.

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

Privacy & Terms