Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Yes, please share it with me so I can help you better.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.AI;

public class YallEeverScript : MonoBehaviour

{

// Token: 0x0600030A RID: 778 RVA: 0x00016852 File Offset: 0x00014A52

private void Start()

    {

        this.agent = base.GetComponent<NavMeshAgent>();

        this.audioDevice = base.GetComponent<AudioSource>();

        this.Wander();

    }

    // Token: 0x0600030B RID: 779 RVA: 0x00016874 File Offset: 0x00014A74

    private void Update()

    {

        if (this.coolDown > 0f)

        {

            this.coolDown -= 1f * Time.deltaTime;

        }

        if (this.warpCool >= 0f)

        {

            this.warpCool -= Time.deltaTime;

        }

        if (this.isDragging & this.playerTouched)

        {

            this.player.position = new Vector3(base.transform.position.x - 1f, 4f, base.transform.position.z);

            this.agent.speed = 60f;

        }

    }

    // Token: 0x0600030C RID: 780 RVA: 0x00016920 File Offset: 0x00014B20

    private void FixedUpdate()

    {

        if (!this.ps.toBase)

        {

            Vector3 direction = this.player.position - base.transform.position;

            RaycastHit raycastHit;

            if (Physics.Raycast(base.transform.position, direction, out raycastHit, float.PositiveInfinity, 3, QueryTriggerInteraction.Ignore) & raycastHit.transform.tag == "Player" & (base.transform.position - this.player.position).magnitude <= 80f & this.warpCool <= 0f)

            {

                this.playerSeen = true;

                this.TargetPlayer();

            }

            else if (this.playerSeen & this.coolDown <= 0f)

            {

                this.playerSeen = false;

                this.Wander();

            }

            else if (this.agent.velocity.magnitude <= 1f & this.coolDown <= 0f)

            {

                this.Wander();

            }

            this.playerTouched = false;

        }

        if (this.warpCool <= 0f)

        {

            this.ps.toBase = false;

        }

    }

    // Token: 0x0600030D RID: 781 RVA: 0x00016A58 File Offset: 0x00014C58

    private void OnTriggerStay(Collider other)

    {

        if (other.tag == "Player" & !this.ps.toBase)

        {

            this.isDragging = true;

            this.playerTouched = true;

            this.agent.SetDestination(this.basePosition.position);

        }

    }

    // Token: 0x0600030E RID: 782 RVA: 0x00016AAC File Offset: 0x00014CAC

    private void OnTriggerExit(Collider other)

    {

        if (other.tag == "Player" & this.ps.toBase)

        {

            this.isDragging = false;

            this.playerTouched = false;

            this.Wander();

        }

        this.agent.speed = 15f;

    }

    // Token: 0x0600030F RID: 783 RVA: 0x00016AFC File Offset: 0x00014CFC

    private void Wander()

    {

        this.wanderer.GetNewTargetHallway();

        this.agent.SetDestination(this.wanderTarget.position);

        this.agent.speed = 15f;

        this.playerSpotted = false;

        this.coolDown = 1f;

    }

    // Token: 0x06000310 RID: 784 RVA: 0x00016B9E File Offset: 0x00014D9E

    public IEnumerator CollisionCooldown()

    {

        this.ps.toBase = true;

        yield return new WaitForSeconds(this.warpCool);

        this.ps.toBase = false;

        yield break;

    }

    // Token: 0x06000311 RID: 785 RVA: 0x00016BB0 File Offset: 0x00014DB0

    private void TargetPlayer()

    {

        this.agent.SetDestination(this.player.position);

        this.agent.speed = 25f;

        this.coolDown = 0.2f;

    }

    // Token: 0x06000307 RID: 775 RVA: 0x000167A0 File Offset: 0x000149A0

    private void OnTriggerEnter(Collider other)

    {

        if (other.tag == "Player")

        {

            this.eever.audVal = Mathf.RoundToInt(Random.Range(0f, 1f));

            base.StartCoroutine(this.GrabCool());

        }

        if (grabCollider = baseCollider)

            {

            this.isDragging = false;

            this.playerSpotted = false;

            this.playerTouched = false;

            this.warpCool = 15f;

            }

    }

    // Token: 0x06000308 RID: 776 RVA: 0x0001683B File Offset: 0x00014A3B

    private IEnumerator GrabCool()

    {

        this.Hit.enabled = false;

        yield return new WaitForSeconds(15f);

        this.Hit.enabled = true;

        yield break;

    }

    // Token: 0x0400039F RID: 927

    public Collider Hit;

    // Token: 0x040003A0 RID: 928

    public YallEeverScript eever;

    // Token: 0x040003A1 RID: 929

    public Collider grabCollider;

    // Token: 0x040003A2 RID: 930

    public bool playerTouched;

    // Token: 0x040003A3 RID: 931

    public bool db;

    // Token: 0x040003A4 RID: 932

    public bool playerSeen;

    // Token: 0x040003A5 RID: 933

    public bool enemySeen;

    // Token: 0x040003A6 RID: 934

    public int audVal;

    // Token: 0x040003A7 RID: 935

    public Transform player;

    // Token: 0x040003A8 RID: 936

    public PlayerScript ps;

    // Token: 0x040003A9 RID: 937

    public Transform wanderTarget;

    // Token: 0x040003AA RID: 938

    public AILocationSelectorScript wanderer;

    // Token: 0x040003AB RID: 939

    public float coolDown;

    // Token: 0x040003AC RID: 940

    public float warpCool;

    // Token: 0x040003AD RID: 941

    public bool playerSpotted;

    // Token: 0x040003AE RID: 942

    private NavMeshAgent agent;

    // Token: 0x040003B6 RID: 950

    public AudioSource audioDevice;

    // Token: 0x040003B7 RID: 951

    public Collider baseCollider;

    // Token: 0x040003B8 RID: 952

    public bool isDragging;

    public Transform basePosition;

}

You have to make it so that when the character's distance from the destination is less than 5, the dragging booleans are set to false. I'm not sure if it has something to do with the ps.isBase boolean, as you may want to replace it. This script is kinda long.

Ok well how would you suggest I write it? I'm really bad with colliders. I just tried to rewrite the code but now all he does is run to the base's transform without touching the player and he can't grab the player anymore.

You need to properly check the booleans and ensure components for all objects are set in place. If a boolean is set to false, then the character will wander, however, if the boolean is true, then he will drag the player. Figure the problem out yourself, because I don't really know how to help you from this point on.

Ok, thank you for the help regardless