I’m getting an error cade at lines (7-9,36) about the fact that a field initializer cannot reference the nonstatic field, method, or property.
I tried to find the awnser over the internet but I tried everything but it all didn’t work.
using UnityEngine;
using System.Collections;
public class PickUp : MonoBehaviour {
// The variables for the positions.
float CharacterPositionX = Character.transform.position.x + 3;
float CharacterPositionY = Character.transform.position.y + 3;
float CharacterPositionZ = Character.transform.position.z + 3;
// The Player and the tagged objects.
public GameObject CarryableObject;
public GameObject Character;
void Start() {
// The origin of the objects.
CarryableObject = GameObject.FindWithTag("Carryable");
Character = GameObject.Find("Character");
// The code for determining the position (Put in note mode to deactivate but keep it).
// CharacterPositionX = Character.transform.position.x + 3;
// CharacterPositionY = Character.transform.position.y + 3;
// CharacterPositionZ = Character.transform.position.z + 3;
}
void OnTriggerStay(Collider other) {
if(Input.GetKeyDown("e")) {
// The position relative to the character.
CarryableObject.transform.position.x = CharacterPositionX;
CarryableObject.transform.position.y = CharacterPositionY;
CarryableObject.transform.position.z = CharacterPositionZ;
// The rotation relative to the character.
CarryableObject.transform.rotation = Character.transform.rotation;
// The gravity.
other.attachedRigidbody.useGravity = false;
}
}
}