Unity Cardboard view tracking - ios

I'm looking to track how long a person looks at an object in Unity when using Google Cardboard (building for iOS).
I'm not sure how to go about this. Would it be the same as mouse tracking?
Any direction would be greatly appreciated!

On each update, use a raycast from the position of the camera to determine what (if any) object is directly in front of the camera. Whenever this object changes, calculate the time difference.

Considering that you have already setup GvrReticlePointer and GvrViewerMain prefabs into your scene-
Create a script and add it to the GameObject from the inspector window.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TimeCounter: MonoBehaviour
{
public float timer;
void Update ()
{
timer += Time.deltaTime;
}
}
Hit play and gaze towards the game object. You would find the Timer value in the inspector getting changed. You could also customize the above script and modify to your need.

Related

Why can I not switch scenes in my unity2d iPhone game?

I am attempting to switch screens but it can't, I have browsed multiple forums and none of the solutions have worked. The code I am using is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameMaster : MonoBehaviour
{
public void GoToGameScene()
{
//Application.LoadLevel(1);
SceneManager.LoadScene(1);
}
}
This is my "GameMasterScript" which is attached to my canvas that my button is under, I have also tried attaching it to the main camera but that doesn't seem to work as well.
The following are screenshots of my canvas, button, and my build settings.
This issue I ran into here was dragging an image and adding a button component to it, which made it not work. Simply adding a button to the canvas UI then putting the image on the button allowed it to work properly

3D objects click event in ARCore

How to get click event of 3D object rendered using arcore SDK in android studio?
My requirement is to click that 3D object and show pop up dialog.
This has nothing to do with ARCore. The game engine / framework that you are using is actually responsible for that.
For example, if you are using Unity, you can use Raycasting.
RaycastHit hit;
Ray ray = yourARCamera.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out hit))
{
// Check if what is hit is the desired object
if(hit.tag == "The_Tag_Of_The_Object_You_Are_Looking_For")
{
// User clicked the object.. Do something here..
}
}
Read more here:
https://unity3d.com/learn/tutorials/topics/physics/raycasting
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
ARCore is not supporting this feature. You need to do it by yourself. Most popular way is ray picking method. There is a lot of examples how to use it
In the case of Arcore - Sceneform SDK, after creating the anchor, you simple have to set a listener on your AnchorNode like so
anchorNode.setOnTapListener((hitResult,motionEvent)->{
//Your pop up
});

Unity deploying to xcode in objective-C: how to delay launch screen in didFinishLaunching?

I have created a game in Unity and am deploying to an iPhone by building the project for Xcode and going from there. Unity wraps its projects up and generates the objective-C files in Xcode for you;
I have worked with Swift in the past and have always delayed my launch screens (I know this is bad practice but I am working with someone who would like the splash screen displayed for 3 seconds before the game instead just appearing briefly) by having the application sleep for a few seconds in the applicationDidFinishLaunching method. I need to know how to do this with a Unity project generated with objective-c-
I have tried putting [NSThread sleepForTimeInterval:6.0]; in the
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
function in my UnityAppController.mm file, and while this seems to be the right place the splash screen is still displayed for maybe a second.
How can I delay the splash in a unity project in Xcode?
Actually you can implement this request in the Unity itself.
Create a 2D canvas in your first scene, and make it over everything else like this:
Render Mode: Screen Space - Overlay
Change your splash screen image texture type to Sprite like this
Texture Type: Sprite (2D and UI)
Create an UI Image and assign above sprite as Source Image to cover all screen
Source Image: SplashScreenImage
Create a start script component into canvas object like this one
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CanvasBehaviour : MonoBehaviour
{
public Image backgroundImage;
void Awake() {
StartCoroutine(RemoveBackgroundImage());
}
private IEnumerator RemoveBackgroundImage()
{
Debug.Log("Before Waiting 3 seconds");
yield return new WaitForSeconds(3);
backgroundImage.gameObject.SetActive(false);
Destroy(backgroundImage);
}
}
By doing this, after splash screen, user will only see the same image so he/she will not understand that anything changed.
Since you don't block the UI Thread by making sleep, you can show some basic animation in the canvas and/or prepare your scene behind the background image.

Alternativa3d Change Resolution for iOS in Flash Builder

I have a problem. I did the first example (Alternativa for dummies part I) and it runs fine but only fills 1/4 of the screen when using Air for iOS. How can I change the resolution?
Here is a screenshot:
http://tinypic.com/r/34yo86q/6
Are you using this code to set up the camera?
camera.view= new View (stage.stageWidth, stage.stageHeight);
The problem comes from the fact that those values are not constant during the whole life of the app. When the app starts, it's possible that the stage resizes, and thus you wouldn't be getting the right values.
First you could set those properties (I do this in 99% of my AS3 projects).
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Then add an event listener for stage resize, and in the handler write the stageWidth and stageHeight values to some vars you could then use to init Alternativa's camera. Or maybe wait for the event to trigger before setting up the camera.
stage.addEventListener(Event.RESIZE, checkSize);
The handler
public function checkSize(e:Event):void {
realWidth = stage.stageWidth;
realHeight= stage.stageHeight;
}
Here is Adobe's documentation on the event, with examples on how to use it.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#event:resize

XNA loading/splash screen on game start

I'm trying to have a loading screen that pops up as soon as you run that executable that launches the game, whilst the game loads I want to display an image on the desktop much like how Gamemaker allows you to have a loading image.
I've had a brief look around and most people want an image to be shown whilst they load content which is not what I want, or perhaps it is... =P
My guess would be to set the game window borderless at the start, load the splash screen, draw it, then begin all the main loading (Specifically loading DirectInput through SlimDX takes a while). However would this support having a transparent/irregular shaped image? E.G if I wanted a borderless circle to be displayed whilst the game loads, would that be possible?
Thanks.
It's very simple. Just implement System.Threading and you're done.
Here's how it works, first add:
using System.Threading;
to the top of your class, then add the following things:
//the enum for state types
enum GameState
{
Loading,
StartMenu
}
//Init our gameState enum as variable
GameState gameState;
protected override void LoadContent()
{
gameState = GameState.Loading;
spriteBatch = new SpriteBatch(GraphicsDevice);
device = GraphicsDevice;
Window.Title = "Your Window";
//Other stuff that you had here before, now go in LoadGame()
loadingscreen = Content.Load<Texture2D>("loading");
Thread bgLoad = new Thread(new ThreadStart(LoadGame));
bgLoad.IsBackground = true;
bgLoad.Start();
}
public void LoadGame()
{
//Loading stuff here
gameState = GameState.StartMenu; //or GameState.Playing
}
and then put a loading texture in your Content Project
If I understand you correctly, you essentially want to have a window opened that is not full screen that also lacks the regular border and buttons that accompanies a window.
I can't test this but this should be a good start.
Here!
I would start by creating a bare bones Game1 class that can track an image and keep track of time for a timer.
Later you could add logic that actually tracks the loading of assets in the main program.
To start I'd just test it for a fixed time like 3 seconds.

Resources