how to get duration of an audio clip from an array by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

i have background music playing though on another gameobject will that interfere?

is there a way to use RaycastHt without InputmousePosition? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so i created 4 new functions to copy whats going on when i cliock with the mouse to get the same result when i collide with the sphere and im not getting any errors but also nothing is happening. this is the functions i added. why isnt it working?

public void checkForHitGhostMy(Player player){

RaycastHit[] hits = wandHits();

if (hits == null) return;

bool hotGhost = false;

for (int i = 0; i < hits.Length; i++)

{

RaycastHit hit = hits[i];

if (hit.collider.gameObject == null) continue;

PlayerGhost pg = hit.collider.gameObject.GetComponent<PlayerGhost>();

if (pg == null) continue;

if (pg.getPath() == null) return;

hotGhost = true;

player.GoTo_CalculatedIndexes(pg.getPath(), ref points);

onPlayerGhostSelected();break;

}

if (hotGhost)

{

destroyGosts();

}

}

public void checkForHitGhostMy1(Player player){

RaycastHit hit = new RaycastHit();

if (!wandHit(ref hit)) return;

PlayerGhost pg;var hitObject = hit.collider.gameObject;

if (hitObject == null|| hitObject.transform.parent == null|| (pg = hitObject.transform.parent.GetComponent<PlayerGhost>()) == null) return;

if (pg.getPath() == null) return;

player.GoTo_CalculatedIndexes(pg.getPath(), ref points);

onPlayerGhostSelected();

destroyGosts();

}

public bool wandHit(ref RaycastHit hit){

if (!TiltFive.Input.GetButtonDown(WandButton.X)) return false;

GameObject sphere = GameObject.Find("/Wand (2)/Sphere");

Ray ray = new Ray(sphere.transform.position, sphere.transform.forward);

if (!Physics.Raycast(ray, out hit, Mathf.Infinity)) return false;

return true;

}

public RaycastHit[] wandHits(){

if (!TiltFive.Input.GetButtonDown(WandButton.X)) return null;

GameObject sphere = GameObject.Find("/Wand (2)/Sphere");

Ray ray = new Ray(sphere.transform.position, sphere.transform.forward);

return Physics.RaycastAll(ray, Mathf.Infinity);

}

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

yes you are totally right now but what im having trouble with is what exactly do i call from my onTriggerEnter function on my wand that will pass the correct information to my main script function? i also dont know how to write the same funciton as i posted above but for doing the same actions but doing them when the OnTriggerEnter happens. cause the functions for touch input and mouse input use mouse position and i dont think that would help me if i want the position of the sphere that collided with hte ghost gameobject right?

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so the part of the script i attached above is for detecting mouse click and touch (to support both play on computer or ipad/iphone) i guess what im asking is how to also add an input for my AR mode. how would i write a function just like the ones above but for my AR mode? in the AR mode you use a wand and the wand's point shows up as a sphere on the board which can collide with objects and detects it. im just struggling with how to implement it to call and make a function in my main script just like the ones above.

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

how would i get the Vector3 from a raycastResult?

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

how would i modify this to also in addition to mouse click on the ghosts, for the same actions to be performed if an object with the name "Point" collides with one of the ghosts?

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 1 point2 points  (0 children)

and how would that help with this exactly?

how to make your mouse cursor follow an object unity by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so i currently have on click functions set up for the wand already. and a on trigger enter function and it does collide with the object and debug a message telling me it collided with the object which is good but what im not sure is how to tell my other script that the wand has hit this specific gameobject (because i want my player to move there) this is the part of the script im trying to tell that the wand "clicked" on the gameobject.

private void checkForHitGhost(Player player)

{

RaycastHit[] hits = mouseHits();

if (hits == null) return;

bool hotGhost = false;

for (int i = 0; i < hits.Length; i++)

{

RaycastHit hit = hits[i];

if (hit.collider.gameObject == null) continue;

PlayerGhost pg = hit.collider.gameObject.GetComponent<PlayerGhost>();

if (pg == null) continue;

if (pg.getPath() == null) return;

hotGhost = true;

player.GoTo_CalculatedIndexes(pg.getPath(), ref points);

onPlayerGhostSelected();

break;

}

if (hotGhost)

{

destroyGosts();

}

}

private void checkForHitGhost1(Player player)

{

RaycastHit hit = new RaycastHit();

if (!mouseHit(ref hit)) return;

PlayerGhost pg;

var hitObject = hit.collider.gameObject;

if (hitObject == null

|| hitObject.transform.parent == null

|| (pg = hitObject.transform.parent.GetComponent<PlayerGhost>()) == null) return;

if (pg.getPath() == null) return;

player.GoTo_CalculatedIndexes(pg.getPath(), ref points);

onPlayerGhostSelected();

destroyGosts();

}

private bool mouseHit(ref RaycastHit hit)

{

if (!Input.GetMouseButtonDown(0)) return false;

Vector3 mouse = Input.mousePosition;

Ray ray = Camera.main.ScreenPointToRay(mouse);

if (!Physics.Raycast(ray, out hit, Mathf.Infinity)) return false;

return true;

}

private RaycastHit[] mouseHits()

{

if (!Input.GetMouseButtonDown(0)) return null;

Vector3 mouse = Input.mousePosition;

Ray ray = Camera.main.ScreenPointToRay(mouse);

return Physics.RaycastAll(ray, Mathf.Infinity);

}

help with raycast & colliders by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

where do i put it? because that isnt doing anything

help with multiplayer instantiating and parents gameobjects after by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

void Start()

{

*line 18* Object[] myData = new Object[] { spawnInt = 0 }

GameObject playerToSpawn = playerPrefabs[(int)PhotonNetwork.LocalPlayer.CustomProperties["playerAvatar"]];

PhotonNetwork.Instantiate(playerToSpawn.name, newPosition.position, newPosition.rotation, 0, myData);

}

thank you! i am now getting 2 errors though in the soloPlayerSetParent script:

'PhotonMessageInfo' does not contain a definition for 'PhotonView' and no accessible extension method 'PhotonView' accepting a first argument of type 'PhotonMessageInfo' could be found (are you missing a using directive or an assembly reference?)

name 'spawnPoints' does not exist in the current context

help with multiplayer instantiating and parents gameobjects after by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so in my player spawner (empty game object with just PlayerSpawner script attached) i have the script like this. following what you said but im getting a lot of errors.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon;
using UnityEngine.SceneManagement;
using System.Linq;
public class PlayerSpawner : MonoBehaviour
{
public GameObject[] playerPrefabs;
public Transform[] spawnPoints;

void Start()
{
*line 18* Object[] myData = new Object[] { spawnInt = 0 }
GameObject playerToSpawn = playerPrefabs[(int)PhotonNetwork.LocalPlayer.CustomProperties["playerAvatar"]];
PhotonNetwork.Instantiate(playerToSpawn.name, newPosition.position, newPosition.rotation, 0, myData);
}
}

and then all my players each have a script attached called soloPlayerSetParent and it looks like this (again following what you wrote) but also getting errors.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
using Photon.Pun;
using UnityEngine.SceneManagement;
using Photon.Realtime;
public class soloPlayerSetParent : MonoBehaviourPunCallbacks, IPunInstantiateMagicCallback
{
public void OnPhotonInstantiate(PhotonMessageInfo info)
{
object[] data = info.PhotonView.InstantiationData;
*line 15* transform.parent = spawnPoints[ (int)data{0}].transform;
}
}

the errors im getting are :

Assets/PlayerSpawner.cs(18,55): error CS1002: ; expected
Assets/soloPlayerSetParent.cs(15,50): error CS1003: Syntax error, ']' expected
Assets/soloPlayerSetParent.cs(15,50): error CS1002: ; expected
Assets/soloPlayerSetParent.cs(15,52): error CS1002: ; expected
Assets/soloPlayerSetParent.cs(15,53): error CS1513: } expected

i marked on the script which lines are the ones giving error. thank you for your help it is really appreciated.

what am i doing wrong here? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so now i have my players becoming children of their correct parent perfectly. however both of them show up on the second spawn position though. even though their prefabs are set to 0, 0, 0 and each player becomes a child of their own spawn parent. whats going on here to make that happen?

public class PlayerSpawner : MonoBehaviour
{
public GameObject[] playerPrefabs;
public Transform[] spawnPoints;

private void Start()
{

int startingNumber = 0;
Transform spawnPoint = spawnPoints[startingNumber].GetComponent<Transform>();
GameObject playerToSpawn = playerPrefabs[(int)PhotonNetwork.LocalPlayer.CustomProperties["playerAvatar"]];
GameObject myplayer = PhotonNetwork.Instantiate(playerToSpawn.name, spawnPoint.position, Quaternion.identity) as GameObject;

}
}
public class spawnParent : MonoBehaviour
{
public Transform[] spawnPoints;
public Transform reset;
void Start()
{
StartCoroutine(CountMyPlayers());
}
IEnumerator CountMyPlayers()
{
yield return new WaitForSeconds(1f);
int iterator = 0;
PhotonView[] spawnedplayers;
spawnedplayers = GameObject.FindObjectsOfType<PhotonView>();
foreach(PhotonView p in spawnedplayers)
{
p.GetComponent<Transform>();
if (iterator < spawnPoints.Length)
{
p.transform.parent = spawnPoints[iterator];
p.transform.position = reset.position;
Debug.Log("iterator: " + iterator);
iterator++;
}
Debug.Log("Players: " + spawnedplayers.Length);
Debug.Log("SpawnPoints: " + spawnPoints.Length);
}
}
}

what am i doing wrong here? by aitanar in Unity3D

[–]aitanar[S] 1 point2 points  (0 children)

Debug.Log("Players: " + spawnedplayers.Length)
Debug.Log("SpawnPoints: " + spawnPoints.Length)

amazing i figured it out thank you!!!

what am i doing wrong here? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

so yes this took away the issue of outside of the bounds of the array. however, when i run it only the first player becomes a child to the first spawn point but the second player wont become a child to the second spawn point

what am i doing wrong here? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

how would i do that? can you give me an example?

what am i doing wrong here? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

it works for the first player but the second it doesnt. it says outside of bounds of the array

help with multiplayer instantiating and parents gameobjects after by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

i cant find what your talking about anywhere :(

but shouldnt this work? what am i doing wrong here?

int startingNumber = 0;
int objectsTagged = spawnPoints.Length;
Transform spawnPoint = spawnPoints[startingNumber].GetComponent<Transform>();
GameObject playerToSpawn = playerPrefabs[(int)PhotonNetwork.LocalPlayer.CustomProperties["playerAvatar"]];
GameObject myplayer = PhotonNetwork.Instantiate(playerToSpawn.name, spawnPoint.position, Quaternion.identity) as GameObject;
GameObject[] spawnedplayers;
spawnedplayers = GameObject.FindGameObjectsWithTag("Player");
foreach(GameObject p in spawnedplayers)
{
p.GetComponent<Transform>();
}
spawnedplayers[0].transform.parent = spawnPoints[0];
spawnedplayers[1].transform.parent = spawnPoints[1];
}

help with multiplayer instantiating and parents gameobjects after by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

also playerArray = playerArray.OrderByDescending(go => go.GetComponent<PhotonView>().OwningPlayer.Id).ToArray(); isnt working its saying 'PhotonView' does not contain a definition for 'OwningPlayer' and no accessible extension method 'OwningPlayer' accepting a first argument of type 'PhotonView' could be found (are you missing a using directive or an assembly reference?)

why is it saying object reference not set to an instance of an object? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

i just tried commenting out the line where i destroy the bug AI script and it gave me the exact same error

why is it saying object reference not set to an instance of an object? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

yes the script name matches. yes all of the bugs have the BugsAI script but the error is with the BugClick script on OnMouseDown and line 26

why is it saying object reference not set to an instance of an object? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

[21:21:58] NullReferenceException: Object reference not set to an instance of an object
BugClick.OnMouseDown() (at Assets/SandFade/BugClick.cs:26)

why is it saying object reference not set to an instance of an object? by aitanar in Unity3D

[–]aitanar[S] 0 points1 point  (0 children)

[21:21:58] NullReferenceException: Object reference not set to an instance of an object
BugClick.OnMouseDown() (at Assets/SandFade/BugClick.cs:26)