Posts

Showing posts with the label unity3d

How can I change Parent object's position in Unity

Image
How can I change Parent object's position in Unity Image: I am trying to make it move entire Inventory object when dragging "NamePanel" object. I added this script to "NamePanel" object and it makes only NamePanel to move. How should I edit my script to do that? how can I get Parent's transform component? since I'm not a English speaker, it's hard to get information by only searching... public class InventoryControl : MonoBehaviour, IBeginDragHandler, IDragHandler { ///////////////////////////////////////////////////////////////////////////////////// public Vector3 offset; public void OnBeginDrag(PointerEventData eventData) { offset = transform.position - (Vector3)eventData.position; } public void OnDrag(PointerEventData eventData) { transform.position = (Vector3)eventData.position + offset; } ////////////////////////////////////////////////////////////////////////////////////// } ...

unity c# - how to get values of list

unity c# - how to get values of list<object> I have this json: [ [ [ "Tel Aviv", "Beersheba", "Jerusalem", "Haifa" ] ], [ { "City": "Tel Aviv" }, { "City": "Beersheba" }, { "City": "Jerusalem" }, { "City": "Haifa" }, { "City": "Jerusalem" }, { "City": "Tel Aviv" }, { "City": "Haifa" }, { "City": "Beersheba" }, { "City": "Jerusalem" }, { "City": "Jerusalem" }, { "City": "Haifa" }, { "City": "Tel Aviv" }, { "City": "Tel Aviv" }, { "City": "Beershe...

Recommended process for saving Custom C# Classes (containing lists/arrays of various size) other than binaryformatter.serialize?

Recommended process for saving Custom C# Classes (containing lists/arrays of various size) other than binaryformatter.serialize? I would like users to be able to create grid-style 'maps' in my application, save them to disk and then share them with others. Among basic map data I would like the user to enter their name so as to 'claim' their work. For this to be a little bit more secure I was thinking of saving the map class (with the artists name, map dimensions, other useful options and the flat/2D array/list [delete as necessary]) into binary. So, XML's (being human readable) are probably not what I'm going to be using... but I'm not completely dead set against them yet, just cautious to stop 'stealing'. I've been using the BinaryFormatter.Serialize method, however as the size of my tiledata grows from 200*200 tiles to 300*300 tiles the time it takes to deserialize grows from 6.5 seconds to 33 seconds, and continues to increase in an exponent...

Yet another onTriggerEnter()

Yet another onTriggerEnter() I am aware that many have already posted their problems with this command. I have tried all the differen recommendations but I am still unable to get the onTriggerEnter method to work for me. I am following a set of tutorials and the objective is to create sort of a minigame in which you, using the FirstPersonCharacter controller collect coins. The FirstPersonCharacter has a RigifBody attached to it, Gravity is applied and it is Kinematic, the "Player" tag is applied to the object. The coin has a a rotation script (one of the default assets), a mesh collider with the Is Trigger checkbox and the collection script. The "Coin" tag is applied to this game object and it is static. public class collect : MonoBehaviour { private void onTriggerEnter(Collider c0ol) { Debug.Log("Registered Trigger"); } private void onCollisionEnter(Collision col) { Debug.Log("Registered Collision"); } } I...

Unity serialized objects in different Lists not equal after pressing Play

Unity serialized objects in different Lists not equal after pressing Play basicly I have these lists: [System.Serializable] public class PatrolGraph : MonoBehaviour { public List<Node> nodes = new List<Node>(); public List<Edge> edges = new List<Edge>(); [...] } I generate both Lists (nodes and edges) using a method I run from the editor. Node and Edge are both serializable, and Edge containes two Nodes. However, after I hit play, the Nodes saved in the Edge objects of the edges list don't seem to be the same as the Nodes in my nodes list (NodeA.Equals(NodeB)), even though they should be. If I run the function to generate the Lists during Playmode (the same one I run in edit mode), the Equals function suddenly returns true. Here is the code for the Node and Edge classes: Node: [System.Serializable] public class Node { public float lastVisited = 0; public Vector3 position; } Edge: [System.Serializable] public class Edge { public Node A; public Node B; public ...

Give the player some friction when moving after being pushed

Image
Give the player some friction when moving after being pushed Not really sure how to word this but lets say you are a ball and are bouncing around and moving. Its a flat surface so everything moves fine. Now introduce some 45 degree ramps. You fall on one straight down and bounce away from it. At the moment you can instantly move back regardless of how soon you hit it or what angle or speed your traveling at where it should be harder from the momentum of the push because it was at an angle. Kind of like a small gradual momentum until you reach 0 velocity, then you can move normally. if (playerLeft) { float xVelocity = (playerBody.velocity.x > 0) ? playerBody.velocity.x - playerSpeed : -playerSpeed; playerBody.velocity = new Vector3(xVelocity, playerBody.velocity.y, 0); } if (playerRight) { float xVelocity = (playerBody.velocity.x < 0) ? playerBody.velocity.x + playerSpeed : playerSpeed; playerBody.velocity = new Vector3(xVelocity...

Emgucv Image to LoadRawTextureData

Emgucv Image to LoadRawTextureData I need help for converting Emgucv videoCapture image to LoadRawTextureData of unity to display images/videos in Unity3d 2018.1. I am able to display images but it show strange lines and distorted image effects or some kind of shuttering/scattering. I read the question in this post and apply the solution but the problem is not solved Convert Mat to Texture2d(Stackoverflow) I think the Colorspace of Emgucv image did not matched with the texture2d. Code: void Start () { vc = new VideoCapture(0); vc.FlipVertical = true; //The image I am getting from webcam is flipped myMaterial = GetComponent<Renderer>().material; frameHeight = (int)vc.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight); frameWidth = (int)vc.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth); camera = new Texture2D(frameHeight,frameWidth, TextureFormat.RGB24, false,false); } I am getting images in this part of code and converting the color space as p...

Confirm ARHit Ready

Confirm ARHit Ready I am using Unity with Apples's ARKitHitTest script. I have created a prompt on the UI that asks the user to point at the ground and scan. What I am trying to do is determine when the ARKit has enough points scanned to place target. Once I figured out how this is done I can then update the user Prompt to say ready to place. Can anyone please advise how I determine when ARKit is ready to place? Thanks! 1 Answer 1 ARKit has a number of methods which you can utilise to determine whether tracking is available, and whether for example conditions are not ideal for tracking. These can be obtained in Unity by registering for the following callbacks: Unity UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated; UnityARSessionNativeInterface.ARSessionFailedEvent += ARSessionFailedEvent; These can help you to determine whether tracking is available or limited for example. E...