I am using Unity Playground with students and we are trying to use the PICK-UP AND HOLD script, but we don't think it is working properly. We have everything mentioned in the reference guide on the object, but the character doesn't pick up the object. When the is trigger is marked the player will just go through the object. When the is trigger is marked off, the player will collide with the object and it moves. Clicking the button to pick up the object just causes the object to float through colliders but the game object doesn't follow the character. I am guessing something is wrong with the parent-child part of the script but unsure as there are no errors. Here is the script down below.
Thanks!
PICKUP Script Part 1
Part 2
Related
I am creating a canvas with a table containing TextmeshPro Input fields on a row. I'm using the XR Input System for the Oculus Quest Vr Headset and wish to handle input from the controllers so they can interact with the Input fields (Select and DeSelect).
There will be many Rows on this canvas and the number of rows can vary according to the data they look up. So they have to be added dynamically
The input fields are part of a GameObject collection.
I've created a prefab for this collection.
I modified the prefab by placing it in a scene. Assigned to the GameObject the Callback scripts for "On Select" and "On DeSelect" and updated the prefab.
When I check the updated prefab, I see that it has lost the callback references. So I assume they need to be added in code after the GameObject has been instantiated. Can this be done or is this the wrong approach?
Mark
Ok, so I've found a solution to my own question.
I've created a script in the root prefab object.
The child callback then references the root prefab and relevant functions within the prefabs said script.
The code in the root script can pass reference or search for any global gameobjects that need to be aware of the interaction and call their callbacks.
The script is automatically saved along with the prefab and accessible for every instantiation.
Problem solved!
I am making a fps in unity and a game mechanic that I am trying to get is wall running/jumping
I have watched many tutorials but they cant fix the trouble I am having. To understand the code I need to explain the wall run. Basically what happens is that I have an empty game object
that raycast the left and the right of the player detecting for a wall. if it finds a wall and I'm holding left or right button (depending on what side the wall is on) it will add a force pushing the player towards the wall and another force pushing me forward. if I jump of the wall it will add a force depending on where I jumped. to make sure it was working I made a bool Value called iswallrunning but its never been set to true. can I get help with this
Code: https://github.com/ZeeScratcher/Project-robot-game/blob/main/WALLRUN.cs
Looking from the code:
you should only write code into the methods which they are responsible for. In StartWR() do not call StopWR(). This will be done in CheckForWR().
I don't know where Orientation comes from. I suppose this is from a child game object. This is fine, for a test replace Orientation by transform.
You can visualize the rays with Debug.DrawLine().
Better apply the physical force from the event FixedUpdate() instead of Update().
It is safer and more performant to cache with GetComponent() in the Awake or Start method instead of Update. If you are next to a wall in the first frame you will get a null pointer error otherwise.
Check if your walls match your given physical LayerMask and the walls have colliders.
If it is easier for you write all code into the Update() method and split it later into methods.
It would be nice to upvote my message, so I can finally make comments in Stackoverflow.
Kind Regards,
Chris
I am trying to create an AR app using Unity & Vuforia. I have a 3D model that needs to be spawned when ground plane is detected.But this needs to happen only once.
The way Vuforia work is, it keeps on spawning objects when new plane is detected. So what i need to do is either detect plane only once or spawn the object only once. As i am new to Unity, i need help doing this. Great if someone could tell me what i need to do to achieve this.
Vuforia has updated.Now There is no DeploymentStageOnce script.Inorder to stop duplicating while we touch, we have to turn off Duplicate Stage in Content Positioning Behaviour (Script)Check the Inspector when we click Plane Finder.
In your app you should have a Plane Finder object somewhere with the following properties set by default
The Plane Finder object has a Behaviour component attached that calls a Position Content method if a plane was found. That method belongs to the Content Positioning Behaviour and it makes an instance (Clone) of your Ground Plane Stage. In order to avoid more than one instance you should import the vuforia Deploy Stage Once script located here: https://library.vuforia.com/articles/Solution/ground-plane-guide.html and you should change the Plane Finder Behaviour as the following:
I struggled a long with it, in short we must disable AnchorInputListenerBehaviour after hit.
I attached a new script on PlaneFinder with this code below:
<!-- language-all: c# -->
public void OnInteractiveHitTest(HitTestResult result)
{
var listenerBehaviour = GetComponent<AnchorInputListenerBehaviour>();
if (listenerBehaviour != null)
{
listenerBehaviour.enabled = false;
}
}
I added event on Plane Finder Behavior
That's all, I hope it will be useful.
For Updated Versions:
go to "Advanced" setting and "On Interactive Hit Test" script -> Select "Off" option for the script.
Most of the answers are correct but kind of obsolete, the correct way to do that is by code.
Create for example a gameObject called GameManager and pass the GroundPlaneStage and a prefab of the object you want to spawn to a script attached to that GameManager for example call it GameManagerScript.cs, and create a small function called spawnObjects which does the following:
public class SceneManagerScript : MonoBehaviour {
public GameObject objPrefab;
public GameObject ground;
private int count = 0;
public void spawnObject() {
Instantiate(objPrefab, new Vector3(count, 0, 0), Quaternion.identity, ground.transform);
count += 2;
}
}
then after that go to the PlaneFinder specifically to the PlaneFinderBehaviour.cs component you will have callbacks for OnInteractiveHitTest and OnAutomaticHitTest, in your case you need the OnAutomativeHitTest, click + and add a new callback (the function spawnObject in code above like in the image below)
also when you instantiate the object of your preference via the prefab don't forget to write the proper position updates to prevent the objects from getting added in the same position
also don't forget to make the GroundPlaneStage the parent of the object and realize that the position you are adding in the Instantiate() function is relative to that parent (GroundPlaneStage which is represented in the code above with the variable ground)
Finally don't forget to uncheck Duplicate Stage from the "Content Positioning Behaviour" component in the Plane Finder as shown in the picture below:
I hope that helps
please try the vuforia website for this problem
Introduction to Ground Plane in Unity
Recently i came across developing a RPG game as diablo and basically the movement control needs to be carefuly made and verify every element we click before move. I was wondering by having alot of prefab of enemy gameobject, the UI and myself if i must verify by the elements with the tag i want or by the gameobject.
Well for example if i have all UI gameobjects with tag UI and enemys with tag enemy, is it good to verify by tag instead of verying directly by the gameobject name? I'm quite confused with i should use.
This depends on how many GameObjects you are verifying and how often you do it. If you don't this every frame or very often then don't worry about it. If you do it every frame or very often then check the GameObject by tag instead of by name but make sure to use the GameObject.CompareTag function to do so not with the GameObject.tag variable.
The reason is because GameObject.name and GameObject.tag allocates memory. GameObject.CompareTag does not.
I'm making a 2D game where my character can go in and back out from different rooms, so since every room is a different scene I need to be able to somehow keep my character throughout every single scene, for that purpose unity offers DontDestroyOnLoad()
So I did use that function whenever I'm switching my scenes, however there is a problem with that.
Let's assume that my rooms are only 2 and they are really simple looking like this
Here in this scheme the main room is the one that you start your game in, it contains already spawned prefab of the character. Once we go to the second room my character is being saved with all his good stuff, however if we go back to the main scene/room we can now see 2 characters. Why ? Because our initial character is not being destroyed when different scene are loaded and we also have one that is being created along with the Main room/scene. Now this is really nasty and I don't know how to fix that, I also have the same problem with some scripts that I need throughout every single scene. Any help is appreciated.
You can make the character spawn in the main scene through script - instantiate it. Make sure you give the character prefab a certain tag ("Player" for example).
Then instantiate the character inside an if statement. Using FindGameObjectWithTag(<Tag>) == null you can find out if the character was already created.
public GameObject player;
if(GameObject.FindGameObjectWithTag("Player") == null){
player = Instantiate(prefab,position,rotation) as GameObject;
}
The normal solution is you don't create objects that are set to DontDestroyOnLoad in scenes that can be viewed more than once.
What most people do is create a pre-load scene that is the very first scene that loads with the game that creates all objects that survive between scenes, then that pre-load scene loads the "Main game scene".
If you don't want a pre-load scene then your game object needs to check on on Awake if another instance of the game object already exists. If it does find a instance then it needs to destroy itself. The first instance won't find any other instances so it won't be destroyed but all future instances will be.