I have two scripts named Gravity and Planet and I keep getting the error
Assets/Gravity.cs(41,35): error CS0119: Expression denotes a method group', where a
variable’, value' or
type’ was expected
using UnityEngine;
using System.Collections;
public class Gravity : MonoBehaviour {
public Rigidbody rb;
//Holds the Vector3 for gravity
Vector3 gravity;
//Holds all GameObjects in the scene with the tag of Targetable.
GameObject [] targetable;
//The closest GameObject
public GameObject targeted;
// Use this for initialization
// Used to calculate which GameObject is closer.
public float minDist;
public float dist = 0;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
//Fills the array with GameObjects
targetable = GameObject.FindGameObjectsWithTag ("HasGravity");
foreach (GameObject target in targetable) {
//Stores the shortest distance and sets "targeted" to the shortest distance.
dist = Vector3.Distance (transform.position, target.transform.position);
//checks to see which is closer
if (dist < minDist) {
minDist = dist;
targeted = target;
} else if (minDist == 0) {
targeted = target;
minDist = dist;
}
}
//Get the Vector3 for gravity based on current position
gravity =targeted.GetComponent<Planet>.GravityType(transform.position);
}
using UnityEngine;
using System.Collections;
public class Planet : MonoBehaviour {
public enum Planetary{BasicPlanet, DiskPlanet, Hallow, Tube};
public float GravityWell;
public float GravityStrength;
public Planetary PlanetType;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public Vector3 GravityType(Vector3 playerPos){
Vector3 gravityDirection;
switch (PlanetType){
case Planetary.BasicPlanet:
gravityDirection = playerPos - transform.position;
return gravityDirection;
break;
default:
return new Vector3 (0,0,0);
}
}
}
I am trying to call the method “GravityType” from the planet script in the Gravity script.