I tried looking at other CS0120 errors but those didn’t help me in my problem.
using System;
using UnityEngine;
[Serializable]
public class PlayerScripts : MonoBehaviour
{
public float gameTime = 20f;
public int length = 20;
public int length2 = 0x23;
public float LevelWaitTime = 2;
public string name = "game time";
public string name2 = "Score";
public int PointsToWin = 20;
public float rayDistance;
public int score;
public string tagName;
public int width = 100;
public int width2 = 100;
public int xpos = 10;
public int xpos2 = 10;
public int ypos = 10;
public int ypos2 = 0x19;
public void Start()
{
InvokeRepeating("CountDown", 1f, 1f);
}
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Pressed left click.");
RaycastHit hit = new RaycastHit();
//if (Physics.Raycast(Camera.get_main().ScreenPointToRay(Input.get_mousePosition()), ref hit, rayDistance) && (hit.get_transform().get_tag() == tagName))
// if(hit.transform.tag ==tagName)
// {
// EnemyScriptCsharp = hit.transform.GetComponents(typeof(EnemyScriptCsharp));
// EnemyScriptCsharp.numberOfClicks -= 1;
//
// if(EnemyScriptCsharp.numberOfClicks == 0)
// {
// score += EnemyScriptCsharp.enemyPointWorth;
// }
// }
if (hit.transform.tag == tagName)
{
hit.transform.GetComponent(typeof(EnemyScriptCsharp));
EnemyScriptCsharp.numberOfClicks --; //here error CS0120
if (EnemyScriptCsharp.numberOfClicks == 0) //here error CS0120
{
score += EnemyScriptCsharp.enemyPointWorth; //here error CS0120
}
}
}
}
public void CountDown()
{
if (--gameTime == 0)
{
CancelInvoke("CountDown");
if (score >= PointsToWin)
{
Application.LoadLevel("sceneScreenWinMenu");
}
else
{
Application.LoadLevel("sceneScreenLoseMenu");
}
}
}
public void OnGUI()
{
GUI.Label(new Rect((float) xpos, (float) ypos, (float) width, (float) length), "Score: " + score);
GUI.Label(new Rect((float) xpos2, (float) ypos2, (float) width2, (float) length2), "GameTime: " + gameTime);
}
}
And Here is the section with the error
if (hit.transform.tag == tagName)
{
hit.transform.GetComponent(typeof(EnemyScriptCsharp));
EnemyScriptCsharp.numberOfClicks --; //here error CS0120
if (EnemyScriptCsharp.numberOfClicks == 0) //here error CS0120
{
score += EnemyScriptCsharp.enemyPointWorth; //here error CS0120
}
}
and here is what it is suppose to reference
using UnityEngine;
using System.Collections;
public class EnemyScriptCsharp : MonoBehaviour
{
public int enemyPointWorth = 1;
public Transform explosion;
public int numberOfClicks = 2;
public float respawnWaitTime = 2f;
public Color[] shapeColor;
private int storeClicks = 0;
// Methods
public void RandomColor()
{
if (shapeColor.Length > 0)
{
int newColor = Random.Range(0,shapeColor.Length);
renderer.material.color = shapeColor[newColor];
}
}
public void Start()
{
storeClicks = numberOfClicks;
Vector3 startPosition = new Vector3( Random.Range(-6, 6), Random.Range(-4.5f, 4.5f), 0);
transform.position = startPosition;
RandomColor();
}
public void Update()
{
if (numberOfClicks <= 0)
{
if (explosion)
{
Instantiate(explosion,transform.position,transform.rotation);
}
Vector3 position = new Vector3(Random.Range(-6, 6), Random.Range(-4.5f, 4.5f), 0);
RespawnWaitTime();
transform.position = position;
numberOfClicks = storeClicks;
}
}
//public
IEnumerator RespawnWaitTime()
{
renderer.enabled = false;
RandomColor();
yield return new WaitForSeconds(respawnWaitTime);
renderer.enabled = true;
}
}