It looks like you're new here. If you want to get involved, click one of these buttons!
i trying to using UnityStandardAssets.Characters.FirstPerson but it don't work, can you help me? Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class PortalManager : MonoBehaviour
{
[SerializeField]
private Portal firstPortal;
[SerializeField]
private Portal secondPortal;
[SerializeField]
private Transform playerCam;
private float magnitude;
private Vector3 velocity;
private RaycastHit hit;
[SerializeField]
private LayerMask rayMask;
private List<objectPortal> currentObjects = new List<objectPortal>();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void PortalObject(bool isFirstPortal, GameObject currentObj)
{
objectPortal objectToCheck = GetObjectPortalByGameObject(currentObj);
if (currentObjects.Contains(objectToCheck))
{
if (isFirstPortal && objectToCheck.currentPortal == firstPortal)
return;
if (!isFirstPortal && objectToCheck.currentPortal == secondPortal)
return;
currentObjects.Remove(objectToCheck);
}
Rigidbody tempRigid = currentObj.GetComponent<Rigidbody>();
Vector3 pos = Vector3.zero;
Vector3 rot = Vector3.zero;
magnitude = tempRigid.velocity.magnitude;
objectPortal newObject = new objectPortal();
Portal newPortal = firstPortal;
if (!isFirstPortal)
newPortal = secondPortal;
pos = newPortal.transform.position;
if (!newPortal.gameObject.activeSelf)
return;
rot = newPortal.transform.rotation.eulerAngles;
velocity = newPortal.transform.forward;
newObject.currentPortal = newPortal;
newObject.currentGameObject = currentObj;
currentObjects.Add(newObject);
tempRigid.velocity = Vector3.zero;
if (currentObj.layer == 8)
pos += newPortal.transform.forward * 1.3f;
currentObj.transform.position = pos;
if(currentObj.layer == 8)
{
currentObj.GetComponent<>
}
else
{
currentObj.transform.rotation = Quaternion.Euler(rot);
}
}
public void SetPortal(Portal currentPortal)
{
if (Physics.Raycast(playerCam.position, playerCam.forward, out hit, 100, rayMask))
{
if (hit.transform.gameObject.layer == 17)
return;
currentPortal.gameObject.SetActive(true);
currentPortal.transform.position = hit.point;
currentPortal.transform.rotation = Quaternion.LookRotation(hit.normal);
}
}
public IEnumerator RemoveObject(objectPortal removeObjectPortal)
{
yield return new WaitForSeconds(0.1f);
if (!currentObjects.Contains(removeObjectPortal))
yield break;
currentObjects.Remove(removeObjectPortal);
}
public objectPortal GetObjectPortalByGameObject(GameObject objectToCheck)
{
for (int i = 0; i < currentObjects.Count; i++)
{
if (currentObjects[i].currentGameObject == objectToCheck)
return currentObjects[i];
}
return new objectPortal();
}
}
[System.Serializable]
public struct objectPortal
{
public Portal currentPortal;
public GameObject currentGameObject;
}