Question by
carlegos · Apr 16, 2019 at 07:18 AM ·
gameobjecttransformcallvoid
How do I call a void form this object? It is stuck in transform.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpinNadeCore : MonoBehaviour
{// The target marker.
Transform Target;
public float KillDist;
[SerializeField]
private TinyEnemy TinyEnemy;
void start()
{
}
// Update is called once per frame
void Update () {
FindClosestEnemy ();
DistanceKill();
}
void FindClosestEnemy()
{
float distanceToClosestEnemy = Mathf.Infinity;
Enemy closestEnemy = null;
Enemy[] allEnemies = GameObject.FindObjectsOfType<Enemy>();
foreach (Enemy currentEnemy in allEnemies) {
float distanceToEnemy = (currentEnemy.transform.position - this.transform.position).sqrMagnitude;
if (distanceToEnemy < distanceToClosestEnemy) {
distanceToClosestEnemy = distanceToEnemy;
closestEnemy = currentEnemy;
Target = currentEnemy.transform;
}
}
Debug.DrawLine (this.transform.position, closestEnemy.transform.position);
}
void DistanceKill()
{
float dist = Vector3.Distance(Target.position, transform.position);
if (dist < KillDist)
{
TinyEnemy = Target.gameObject;
//Tell them that they are crap (KIll)
TinyEnemy.Take1Damage();
//KYS
Destroy(gameObject);
}
}
}
Comment
Please add a more detailed description of your question/problem. Add what is working, what your intention is and describe in detail where you are stuck or an error occures. When there is an error attach the log message.
Your answer

Follow this Question
Related Questions
How can i assign a GameObject to another but only have some of its components? 1 Answer
How to Change Position of a GameObject to another GameObject C# 1 Answer
Change the size of a GameObject in a certain timespan. 0 Answers
Vector3.MoveTowards moving transform 0 Answers
Why does FindObjectOfType().transform return a null reference 1 Answer