Unity - get the dropdown in child - c#

I want to get the dropdown which is a child of OperationContainer.
My code gives the error "GameObject' does not contain a definition for 'dropdown' and no accessible extension method 'dropdown' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)".
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AddToPC : MonoBehaviour
{
public GameObject OperationContainer;
void get_instruction(){
Dropdown function = OperationContainer.transform.GetChild(0).gameObject.dropdown;
}
}
}

Make sure your Dropdown component is attached to the children gameObject and try:
Dropdown function = OperationContainer.transform.GetComponentInChildren<Drompdown()>();

Related

Can't find namespace even when having the 'using'?

I am using Unity and I'm getting a 'The type or namespace name 'Mine' could not be found (are you missing a using directive or an assembly reference?)' error. I know this means that you are usually missing a using statement, but this is not the case this time. Take a look at the beginning of the 2 script at question. The error is flagged at "public WarmList list;"
using UnityEngine;
using Mine;
namespace PolymindGames.BuildingSystem
{
[RequireComponent(typeof(CookingStation))]
//public class CampfireEffects : MonoBehaviour
public sealed class CampfireEffects : MonoBehaviour
{
public WarmList list;
...
}
}
And script 2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mine
{
public class WarmList : MonoBehaviour
{...
}
}
Why can't script one see class 2? I don't think I am doing anything wrong? I have tried so many solutions but nothing works, I keep getting that complier error.

Unable to detect error while using PhotonView.isMine method

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.IO;
using UnityEngine.UI;
public class PhotonPlayerSetup : MonoBehaviourPunCallbacks, IInRoomCallbacks
{
private PhotonView PV;
void Awake()
{
PV = GetComponent<PhotonView>();
}
void Start()
{
if(PV.isMine)
{
}
}
}
While using above mentioned code this error appears:
"PhotonView does not contain a definition for isMine and no
accessible extension method isMine accepting a first argument of
type 'PhotonView' could be found (are you missing a using directive or
an assembly reference?)"
Thank you for choosing Photon!
PhotonView.isMine from PUN Classic was renamed to PhotonView.IsMine in PUN 2.
Make sure to check out the Migration Notes.

C# cant find a unity auto generated class

Okay so I'm learning to use the new InputActions and I've created a C# scripts using
https://prnt.sc/oyaj5l
And this is what I got:
// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class PlayerControls : IInputActionCollection
{
private InputActionAsset asset;
public PlayerControls()
{
///
}
}
But when I try to create an PlayerControls object, I get an error saying
The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)
This is the class where I try to reference it:
using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class FirstPersonController : MonoBehaviour
{
private PlayerControls controls; // ERROR HERE
}
}
Wrap the PlayerControls class in a namespace, then add a using statement in your class that points to the namespace where your PlayerControls class lives.
I solved it!
It looks like Unity has a compile order. I referenced this: http://answers.unity.com/answers/1274460/view.html and managed to solve it after seeing that "Standard Assets" has priority over other assets

Type or namespace name 'IUnzipper' could not be found

I am trying to run a simple implementation of Virtual Buttons in Unity using Vuforia.
My current versions are : Unity 5.6.1
And I'm recieving Type or namespace 'IUnzipper' could not be found (are you using a missing directive or assembly reference?)
My C# Script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class vbScript : MonoBehaviour, IVirtualButtonEventHandler {
GameObject zombie;
// Use this for initialization
void Start () {
zombie = GameObject.Find ("zombie");
GameObject virtualButtonObject = GameObject.Find ("actionButton");
virtualButtonObject.GetComponent<VirtualButtonBehaviour> ().RegisterEventHandler (this);
}
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) {
Debug.Log("button Pressed");
zombie.GetComponent<Animation> ().Play ();
}
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) {
zombie.GetComponent<Animation> ().Stop ();
}
}
Error trace:
\VirtualButton3\Assets\Vuforia\Editor\Scripts\Unzipper\SharpZipLibUnzipper.cs(38,38): Error CS0246: The type or namespace name 'IUnzipper' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Assembly-CSharp-Editor)
Google is a great resource.
It appears that the template dose not always come with it in the folder.
Here is the link to it link

PointToClient not quite working. (Error details within.)

i'm working on a tower defence for a class exam together with a friend of mine. And i figured i would use "PointToClient" To get the positions of the cursor to send with the tower when ever we want to put it down. But its not quite working. I keep getting the error:
'Vp.PlaceTower'does not contain a definition for 'PointToClient' and no extension method 'PointToClient' accepting a first argument of type 'Vp.PlaceTower' could be found (Are you missing a using directive or an assembly reference?).
The code is as follows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
namespace Vp
{
class PlaceTower : GameWorld
{
private List<Tower> towers = new List<Tower>();
private Point cursorPos;
private Point position;
private Point oldCursorPos;
public void PlaceTower()
{
cursorPos = this.PointToClient(Cursor.Position);
}
}
}
PointToClient is a method that belongs to the class System.Windows.Forms.Control. Does GameWord inherit this class? Your exception is very explanatory.
Make GameWorld inherit Control and you will solve this.

Categories

Resources