Browse Author: mohan.rao

How to play movie in iphone using unity3d

this is code used to play the video in iphone using unity 3d

using UnityEngine;

using System.Collections;
public class IntroMovie : MonoBehaviour {

void Start ()  {

iPhoneUtils.PlayMovie(“CINEMATIC_WITH_MUSIC.mp4”,Color.black,

iPhoneMovieControlMode.CancelOnTouch,iPhoneMovieScalingMode.AspectFit);   }

}

one important thing in order to play video files it should be placed in StreamingAssets folder

if the video placed outside it will not work

 

  keno winnings

Screen Orientations Methods in unity3d

There are 3 types of orientation in

Rotate only landscape

public void AutoOrientToLandScape() {

if(Vector3.Dot(Input.acceleration.normalized,new Vector3(1,0,0)) > 0.45)  { Screen.orientation=ScreenOrientation.LandscapeRight; }

else if(Vector3.Dot(Input.acceleration.normalized,new Vector3(-1,0,0)) > 0.45)  { Screen.orientation=ScreenOrientation.LandscapeLeft; } }

Rotate only Portrait

public void AutoOrientToPortrait() {

if(Vector3.Dot(Input.acceleration.normalized,new Vector3(1,0,0)) > 0.45)  { Screen.orientation=ScreenOrientation.Portrait; }

else if(Vector3.Dot(Input.acceleration.normalized,new Vector3(-1,0,0)) > 0.45)  { Screen.orientation=ScreenOrientation.PortraitUpsideDown; } }

Auto Orientation

public void AutoOrient() {

Screen.orientation=ScreenOrientation.AutoRotation; }

How to add an audio file to a button in Unity3D

using UnityEngine;

using System.Collections;

using System;

public class MainMenu : MonoBehaviour {

public AudioSource audioSource;

public AudioClip palySound;

void Start ()  { }

public void OnGUI()

{  if(GUI.Button(new Rect(50,200,100,45),”Play”))  {

audioSource.PlayOneShot(palySound); }

}}

when we attached the script in the inspector.

we have to attach the AudioSource  from the

Components–>Audio–>AudioSource

to the inspector

How to Create Write and Read a file in iphone without using playerprefs in unity3d

it is not that easy to read or write file in iphone we have to give the specific path in order to read or write.
here is the sample code

using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;

public static class GameManager
{
private static string path;

public static void starting ()
{
    path = Application.dataPath.Substring (0, Application.dataPath.Length - 20 )+"Documents";
}

//---------------------file handleres------------------------------

public static void writeToFile(string filename , int value)
{
    StreamWriter sw = new StreamWriter(path+"/"+filename);
    string temp = value.ToString();
    sw.Write("");
    sw.WriteLine(temp);
    sw.Close();
}
public static int ReadFromFile(string filename )
{
    StreamReader sr = new StreamReader(path+"/"+filename);
    string temp = sr.ReadLine();
    int anothertemp = int.Parse(temp);
    sr.Close();
    return anothertemp;
}

//---------------------file handleres------------------------------

}

Each app only have access to “Documents” folder under it. That’s the place we could use to write or read or create.

How to make an AI Enemy Car in which it follows the track during the Race ?

The AI for enemy car can be done by using waypoints method..

the following code is used

var waypoint : Transform[];

var speed : float =20;

private var currentWaypoint : int;

var loop : boolean = true;

function Awake()

{waypoint[0]=transform;}

function Update ()

{ if(currentWaypoint < waypoint.Length)

{ var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target-transform.position;

var velocity = rigidbody.velocity;

if(moveDirection.magnitude<1)

{ currentWaypoint++;}

else { velocity = moveDirection.normalized * speed;  //velocity = Vector3.forward * speed; }  }

else { if(loop)  {  currentWaypoint=0; }

else   { velocity = Vector3.zero; }

} rigidbody.velocity = velocity;

}

 

Weird movment of character in Unity3D

Question:I imported a simple 3d model from which I construtected a terain. For a test I use box(mesh), but movment is really weird like that models would be realy bumpy. Because of that I also tryed to switch my models with unity meshes but it’s same

 

Answer:In ur game select cube in that u have added rigidbody.

In Rigidbody select the constraints in that u will see freeze rotation and freeze position. in which all are uncheck.

now check the freeze rotation in which all should be ticked.

by doing this they will not be any flickers in your game.

  игровые автоматы играть онлайн бесплатно без регистрации и смс 777

Movement from Unity 3d into Unity 3D iOS or Android

if u want to using buttons use this it will work in unity 3d and ios

void OnGUI()
{
    if(GUI.RepeatButton(new Rect(50,210,40,40),"up"))
    {
       transform.Translate(Vector3.forward*Time.deltaTime*50); 

    }

    if(GUI.RepeatButton(new Rect(50,280,40,40),"down"))
    {
       transform.Translate(Vector3.back*Time.deltaTime*50);

    }

    if(GUI.RepeatButton(new Rect(10,250,40,40),"left"))
    {
       transform.Rotate(Vector3.down, 90*Time.deltaTime);
    }

    if(GUI.RepeatButton(new Rect(90,250,40,40),"right"))
    {
       transform.Rotate(Vector3.up, 90*Time.deltaTime);
    }
}

other wise,

u can use joystick for the movement in ios. the standard package is present in standard assets mobile in the unity itself.
so u try it once.
In menu->assets->import package->standard assets(mobile)

 


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box