I am pretty new to Unity and game development so sorry if this is a stupid mistake.
I am trying to create a UI in which you enter text into a input field (TMP), the script will check the input and if it reads "password", a Debug.Log is shown in the console.
I have looked around online for any help with this but nothing seems to work.
I have got a script that I assume to work, but I am getting one major problem: On line 15 it cant find the Input Field that I am trying to reference?
The script is attached to the Input Field, I am trying to reference it from there.
Any help would be greatly appreciated... Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CheckPassword : MonoBehaviour
{
public InputField inputField;
public void Awake()
{
inputField = GetComponent<InputField>();
}
public void CheckInputField()
{
if (inputField.text == "password")
{
Debug.Log("Password Correct");
}
}
}
The problem was that due to the fact that I was using a Text Mesh Pro Input Field I had to specify that in the variable.
Instead I used: [SerializeField] TMPro.TMP_InputField inputField;
And the awake function was not necessary either.
Related
Before that, i apologize if my english is bad.
I made an AR about crystal structure. I will make an AR with 36 crystal structure objects with 9 markers/image target which means 1 marker has 4 objects to be displayed. The concept that I want to make is that these objects are connected to the spawn and destroy system and I managed to make it with the help of tutorials on youtube. but I have a problem, my AR object doesn't want to be on top of the marker/image tergets. if I try to adjust the position of the object, when I try to run it happens that the object is still next to the marker and follows the 0,0,0 coordinates of the object which is not above the marker, even though I have already inserted the object into the marker. I am very confused how to solve my problem.
this is part script for my project to spawn and destroy system:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sistem : MonoBehaviour
{
public static Sistem instance;
public int ID;
public GameObject TempatSpawn;
public GameObject[] KoleksiStruktur;
// Start is called before the first frame update
void Awake()
{
instance = this;
}
void Start()
{
SpawnObject();
}
public void SpawnObject()
{
GameObject Benda = Instantiate(KoleksiStruktur[ID]);
Benda.transform.SetParent(TempatSpawn.transform, false);
Benda.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
Debug.Log("Objek berhasil di-instantiate");
}
}
the object and the marker/image target
i tried to solve the problem by setting the object over the marker but still can't fix it. I hope to find a solution how I can display my object above the marker.
I'm needing to adjust some of the field attributes for the Location.VCashAccountID field on the Vendors screen - AP303000. When I put the code below into a customization DLL, it compiles fine and there are not apparent issues on the screen. However, when I try to publish the customization project with the DLL included, I get an error.
Code:
public class VendorMaintDefLocationExtExt : PXGraphExtension<VendorMaint.DefLocationExt,
VendorMaint>
{
public void _(Events.CacheAttached<PX.Objects.CR.Standalone.Location.vCashAccountID> e) { }
}
Error:
"Method Boolean DoValidateAddresses(PX.Objects.CR.Extensions.ValidateAddressesDelegate) in graph extension is marked as [PXOverride], but the original method with such name has not been found in PXGraph"
What am I missing?
TIA!
The following implementation will override the vCashAccount attribute on AP303000
public class AAVendorMaintDefLocationExtExtension : PXGraphExtension<DefLocationExt, DefContactAddressExt, VendorMaint>
{
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "I am override")]
public void _(Events.CacheAttached<PX.Objects.CR.Standalone.Location.vCashAccountID> e) { }
}
You will also require the following references
using PX.Data;
using PX.Objects.AP;
using static PX.Objects.AP.VendorMaint;
The result can be seen in the snip below
The main difficulty in this task was the multitude of graph extensions utilized by the page. Though it's a beneficial design to encapsulate functionality it can be finnicky to determine which order they should be declared in a new extension.
You're graph extension extends VendorMaint.DefLocationExt which contains DoValidateAddresses. Try just extending VendorMaint.
I have this simple platformer that has coins that you pick up and a canvas that shows the score and changes whenever you pick one up. This is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour {
Text text;
private LVLMang levelManager;
void Start () {
text = GetComponent<Text> ();
levelManager = FindObjectOfType<LVLMang> ();
}
void Update () {
text.text = "" + levelManager.Score;
}
}
It will add in the coins to the score, but it gives me so many errors that my game eventually crashes. The error is: 'NullReferenceException: Object reference not set to an instance of an object' and it highlights the text.text line. Please Help. Thanks in advance.
First, make sure you have a Text component on the object that has the script. Your GetComponent<Text> (); call isn't finding a Text component.
Alternatively you can make Text text; public and hook it to the actual Text component you want to change by drag-dropping the Text-component object into the Script component's Text field.
Secondly, after updating the text.text value, call text.SetAllDirty(); to get the change to take effect.
I am new to unity and want to get a value from a input text field. I found this question
Get text from Input field in Unity3D with C#, but when I execute it the same error always appear: NullReferenceExcpetion : Object reference not set to an instance of an object.
It seems like a stupid mistake and I tried everything but can't seem to fix it.
My code:
void Start () {
var input = gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener(SubmitName);
}
private void SubmitName(string arg0)
{
Debug.Log(arg0);
}
I tried putting InputField input; before the start function and erasing var but still no luck.
If anyone can help me with this problem it would be much appreciated.
Pictures of where my scripts are attached at the moment.
Your code is nearly correct, if you have a look at the documentation, you have to call your method with function before calling the method name. It looks to me like you are mixing c# and JS, here is the `js function:
public class Example {
public var mainInputField;
public function Start() {
// Adds a listener to the main input field
// and invokes a method when the value changes.
mainInputField.onValueChange.AddListener(function() {
ValueChangeCheck();
});
}
// Invoked when the value of the text field changes.
public function ValueChangeCheck() {
Debug.Log("Value Changed");
}
}
the c# solution:
public class MenuController : MonoBehaviour {
[SerializeField]
InputField inputText;
// Use this for initialization
void Start () {
inputText.onValueChange.AddListener(delegate {
DebugInput();
});
}
private void DebugInput(){
Debug.Log ("Input: " + inputText);
}
}
My Hierarchie looks like this:
I created a Canvas and inserted an InputField inside it. The script with the code inside is attached to the Canvas and the InputField connected to the [SerializeField] inside the script in the Canvas.
I would recommend you to make your InputField a class variable, so you can access it easier later. Furthermore you should just create a [SerializeField] for your InputField so you can drag it to your script. This might avoid some mistakes too.
Change InputField(TMP) to InputField(Legacy)
I would like to create a base class for observableObject generic enough for an observable object to derive from, but I hit some technical issue. This is an extract of the class. It is an abstract that implements interface INotifyPropertyChanged. But when I tried to use PropertySupport.ExtractPropertyName, I got compiler error saying 'PropertySupport' not exist in the current context. I am using VS2002. My intention was to create a library to host a small "framework" of my own and use it for different projects. Could anyone more well versed in the reflection point out what was wrong in my code to cause the compiler error?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace MyFramework
{
[Serializable]
public abstract class ObservableObject: INotifyPropertyChanged
{
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler!=null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
{
var propertyName = PropertySupport.ExtractPropertyName(propertyExpression);
this.RaisePropertyChanged(propertyName);
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
}
}
The error you are getting usually refers to a missing using directive or missing reference.
Looking at MSDN for the function you are trying to use it looks like you are missing the using directive Prism.ViewModel
using Microsoft.Practices.Prism.ViewModel;
If this doesn't fix your problem then you need to add a reference to the correct dll
Microsoft.Practices.Prism.Composition.dll
I've never used Prism but after copying your class, adding the correct reference & using directive it built ok.