using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerManager : MonoBehaviour
{
//public GameObject Menu;
RaycastHit hit;
List selectedUnits = new List();
List selectedMenus = new List();
// Update is called once per frame
void Update()
{
//Detect if Mouse is down
if (Input.GetMouseButtonDown(0))
{
//Create a ray from camera to space
var camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
//shoot that ray and get the hit data
if (Physics.Raycast(camRay, out hit))
{
//do something with that data
//Debug.Log(hit.transform.tag);
if (hit.transform.CompareTag("Indicator"))
{
SelectUnit(hit.transform, Input.GetKey(KeyCode.LeftShift));
}
else if (hit.transform.CompareTag("Field"))
{
DeselectUnits();
}
}
}
}
private void SelectUnit(Transform menu, Transform unit, bool isMultiSelect = false)
{
if (!isMultiSelect)
{
DeselectUnits();
}
selectedUnits.Add(unit);
//Menu.gameObject.SetActive(true);
unit.Find("Highlight").gameObject.SetActive(true);
menu.Find("SpawnMarcher").gameObject.SetActive(true);
}
private void DeselectUnits()
{
for(int i = 0; i < selectedUnits.Count; i++)
{
selectedUnits[i].Find("Highlight").gameObject.SetActive(false);
//Menu.gameObject.SetActive(false);
menu.Find("SpawnMarcher").gameObject.SetActive(false);
}
selectedUnits.Clear();
}
}
Hi, this is a script I made by following a tutorial. I am still very new to c# and I'm still trying to get the hang of it. Here I made some edits to the original script and attempted to make the script open a menu as well as the highlighted gameObject appear.(The original purpose of the script was to show selected units in like an rts style but only included the highlight part) Unfortunately I got 2 errors I have no idea how to fix. I am certain that its not a typo error. Any help is appreciated.
I got the following errors:
Assets/Levels/Test/Script/PlayerManager.cs(29,47): error CS1503: Argument 2: cannot convert from 'bool' to 'UnityEngine.Transform'
Assets/Levels/Test/Script/PlayerManager.cs(58,13): error CS0103: The name 'menu' does not exist in the current context
↧