// Use this for initialization void Start() { //set thisparent to be this collider's parent in the hierarchy; i.e. the object that contains the object with this script //thisParent = ; scriptThing = thisParent.GetComponentInParent <ScriptEnemyClass>(); eMove = GetComponentInParent <ScriptEnemyMovement>(); }
public void StartUp() { //Debug.Log("statuseffectclass enabled"); //stacks = new List<StatusEffectClass>(2); switch (entity.name) { case "PlayerCharacter(Unit2)": pData = entity.GetComponentInChildren <PlayerStatScript>(); isPlayer = true; break; case "MeleeEnemy": case "RangedEnemy": eData = entity.GetComponentInChildren <ScriptEnemyClass>(); isPlayer = false; break; default: isPlayer = false; //isSafe = false; break; } //if (isSafe != true) //{ // Destroy(this.gameObject); //this does one thing: removes any unsafe object from existance //} //if(!isPlayer) //{ // if(eData.statHold.whatStatus.FindIndex(statusEffectName) //} InvokeRepeating("IncrementDuration", 0, 0.1f); isDurationRunning = true; }
// Runs whenever this script becomes enabled; this will only run when the enemy can detect the player, then sets the variables necessary void OnEnable() { //Debug.Log("onenable hasrun" + hasRun); //this is one of many debugs; //Debug.Log(detect.firstAwake); if (detect.firstAwake) //if detect hasn't run it's awake function { hasRun = false; //hasRun set to false } if (detect.firstAwake != true) //if detect has already run it's awake function { hasRun = true; //hasRun set to true } Debug.Log("llamaduck" + hasRun); if (hasRun) //if hasRun == (is equal to) true { //if (firstRun) { thisParent = GetComponentInParent<Transform>(); } //else //if (this.gameObject.GetComponent<NavMeshAgent>() != null) // navi = this.gameObject.GetComponent<NavMeshAgent>(); Debug.Log("ONEnableHasRun"); isMovementRunning = true; //set variable to true eClass = GetComponent <ScriptEnemyClass>(); //re/assign eClass detect = GetComponentInChildren <ScriptDetectionRadius>(); //re/assign detect; playerCollider = detect.colliderHolder; //re/assign playerCollider //playerCollider = moveEnd.GetComponentInParent<Collider>(); moveEnd = playerCollider.transform; //set moveEnd to be equal to the transform of the playerCollider playerExents = playerCollider.bounds.extents; //re/assign playerExtents to extents of its collider's bounding box myCollider = GetComponentInParent <Collider>(); //re/assign myCollider; gets the collider data from gameObject's parent myExtents = myCollider.bounds.extents; //re/assign myExtents; as playerExtents above Debug.Log(playerExents + "playerext"); Debug.Log(myExtents + "enemyextents"); Debug.Log(myExtents + playerExents); //these 3 lines output the extents of the player, this enemy, and their combined extents targetStart = thisParent; //i'm not sure why this is here; legacy code? probably could remove it... startPos = transform.position; //re/assigns startPos to the position of this enemy endPos = moveEnd.position - (playerExents + myExtents); //this calculation is used once; sets endpos to be an offset position of moveEnd.position - the combined extents, thus forming a buffer Debug.Log(startPos); Debug.Log(endPos); attackSphere = eClass.attackRange; //re/assigns attackSphere from the eClass variable attackRange { startTime = Time.time; //re/sets starttime to the system time //set end marker to be a the endpoint of a vector with a set magnitude, but a direction of the player object's transform playerLoc = moveEnd.position; //re/sets playerLoc to moveEnd.position; it's weird but necessary for the math to work targetStart = moveEnd; //re/sets targetStart playerLoc = playerLoc = Vector3.ClampMagnitude(playerLoc, speed); //re/sets playerLoc to be a vector3 with magnitude clamped at speed //llama.position = playerLoc; journeyLength = Vector3.Distance(moveStart.position, targetStart.position); //re/sets journey length isLerping = true; //sets isLerping startPos = transform.position; //re/assigns startpos endPos = moveEnd.position - (playerExents + myExtents); //duplicate of above; no harm done if (Mathf.Abs(playerExents.y - myExtents.y) < 1) //if the absolute value of the difference of the y extents is < 1; is there isn't much of a height difference { endPos.y = this.gameObject.transform.position.y; //sets the y value endPos to be the current y position; this is used for preventing enemies from sinking into hte ground } else { endPos.y += playerExents.y - myExtents.y; //otherwise, recalculate endPos.y to be more accurate; note the floating point error } speed = eClass.speed; //insert code to set transforms properly? rotate.speed = speed; //re/sets speed of rotation rotate.playerCollider = playerCollider; //re/sets the playerCollider of rotate rotate.detect = detect; //these really just do the same thing for rotate as they do here rotate.enabled = true; rotate.canRotate = true; } } else { } }