I am making a unity game and I have a script that runs off of 2 others, public class spawner is the one in question, basically I have a UI scroll view with a bunch of different objects and when you click on one you spawn it with the spawner. I am trying to get the size of each unit as they spawn so that it can be offset to be right next to the initial object. This is how I have the spawner code now and I am getting an error of Assets\spawner.cs(15,18): error CS1501: No overload for method ‘GetComponent’ takes 1 arguments I had help with the codes because I am fairly new to coding.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitToggle : MonoBehaviour
{
// Drag & drop the gameObject with the `UnitToggleGroup` component (see below)
public UnitToggleGroup unitToggleGroup;
public GameObject unit;
public event System.Action<GameObject> ObjectOpened;
public int offset;
void Start()
{
unitToggleGroup.Add(this);
}
public void OpenObject()
{
if (unit != null)
{
unit.SetActive(true);
ObjectOpened?.Invoke(unit);
}
}
public void CloseObject()
{
if (unit != null)
unit.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitToggleGroup : MonoBehaviour
{
private List<UnitToggle> toggles = new List<UnitToggle>();
public GameObject SelectedUnit { get ; private set ; }
public void Add(UnitToggle toggle)
{
if(toggles.Contains(toggle))
return;
toggles.Add(toggle);
toggle.ObjectOpened += (GameObject unit) => OnObjectEnabled(toggle, unit);
}
public void OnObjectEnabled(UnitToggle selectedToggle, GameObject unit)
{
foreach(UnitToggle toggle in toggles)
{
if(toggle != selectedToggle)
toggle.CloseObject();
}
SelectedUnit = unit;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class spawner : MonoBehaviour
{
public UnitToggleGroup unitToggleGroup;
public Transform[] spawnLocations;
public int offset;
public void Start() {
offset = GetComponent<Renderer>(unitToggleGroup.SelectedUnit);
}
public void SpawnCurrentlySelectedUnit()
{
//offset = GetComponent<SelectedUnit>;
// offset = GetComponent<Renderer>(UnitToggleGroup.SelectedUnit);
if(unitToggleGroup.SelectedUnit != null){
GameObject unit = Instantiate(unitToggleGroup.SelectedUnit, spawnLocations[Random.Range(0, spawnLocations.Length + offset)].transform.position , Quaternion.Euler(0,180,0)) as GameObject;
}
}
}