Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

GameObject[] doesn't have a definition for transform/name/etc...

$
0
0
I have a pick up script that has GameObject[] for the code FindGameObjectsWithTag. This is my script: using UnityEngine; using System.Collections; using CameraRayCastLine; using PickUpSphereCast; namespace CarryingItems { public class PickUp : MonoBehaviour { // The variables for the positions. // Forward drop offset. public float OffsetDropPosition = 2; // The boolean that checks if the camera's RayCast is hit. public bool CameraRayHit; // The Player and the tagged objects. public GameObject Camera; public GameObject[] CarryableObject; public GameObject Character; public Transform CharacterTransform; // Is an item picked up at the moment? public bool ItemPickedUp; // Are you in the item's SphereCast? public bool InItemSpherecast; // Are you looking at an item? public bool LookingAtObject; void Awake() { // The origin of the objects. Camera = GameObject.Find("MainCamera"); CarryableObject = GameObject.FindGameObjectsWithTag("CarryableObjects"); Character = GameObject.Find("Character"); CharacterTransform = GameObject.Find("Character").transform; // The code that references the RayCast script of the camera. CameraRayHit = Camera.GetComponent().CameraRayCast; // The code that references the SphereCast of another script. InItemSpherecast = PickUpSphereCast.ItemPickUpSphereCast.ItemSphereCast; } void Start() { // The code that tells you how to pick up an object through the debug log. Debug.Log("Press E to pick up an object."); } void Update() { } void PickUpItemCode() { // If another item isn't picked up at the moment. if(ItemPickedUp == false) { Debug.Log("No items picked up."); // If you're in the SphereCast. if(InItemSpherecast == true) { Debug.Log("Spherecast = true."); // If you're looking at the item. if (CameraRayHit == true) { // A boolean for the GUI. LookingAtObject = true; // A code that says you can pick up the item in question. Debug.Log("Press E to pick up the" + CarryableObject.name + "."); // If you press the E key. if (Input.GetKeyDown("e")) { // The position relative to the character. CarryableObject.transform.position = new Vector3(Character.transform.position.x + 1, Character.transform.position.y + 1, Character.transform.position.z + 1); // The rotation relative to the character. CarryableObject.transform.rotation = Character.transform.rotation; // The gravity. CarryableObject.GetComponent().useGravity = false; // A message showing that the object was picked up. Debug.Log("You picked up the " + CarryableObject.name + "! Good for you!"); Debug.Log("Press the left mouse button to use an object."); Debug.Log("Press E to drop an object."); // The code that acitvates the boolean that is needed for the dropping script. ItemPickedUp = true; // The code that makes the chracter the new objects parent. CarryableObject.transform.SetParent(CharacterTransform); } } else { // You're not looking at an object. LookingAtObject = false; } } } else { // The code that makes sure that the pick up boolean is not active when no item is picked up. ItemPickedUp = false; } } void DropItemCode() { // If you're holding an item. if(ItemPickedUp == true){ // If you press the E key. if(Input.GetKeyDown("e")){ // The drop position. CarryableObject.transform.position = new Vector3(CarryableObject.transform.position.x, CarryableObject.transform.position.y, CarryableObject.transform.position.z + OffsetDropPosition); // The gravity gets reenabled. CarryableObject.GetComponent().useGravity = true; } } } void ONGUI() { if(LookingAtObject == true){ // The how to pick up items text. GUI.Label(new Rect(500, 200, 100, 20), "Press E to pick up the" + CarryableObject + "."); } } } }

Viewing all articles
Browse latest Browse all 7934


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>