- Home /
Question by
Rafael_Ayllon · Jun 19, 2019 at 07:49 PM ·
scripting problemscript error
Script Problem
This script consult the transform.position of the object, the problem is that when i attach this script to diferent objects on the scene, doesnt work properly. My question is ¿How to make the script independent for diferents objects, so that it consult the transform.position of each one?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform : MonoBehaviour
{
public float correctHight;
public float playerCorrectSize;
public bool transition;
Controller player;
Collider platformCollider;
void Start()
{
correctHight = transform.position.y + (transform.localScale.y / 2);
player = GameObject.FindObjectOfType<Controller>();
platformCollider = GetComponent<Collider>();
}
void Update()
{
playerCorrectSize = (player.transform.position.y - (player.transform.localScale.y / 2));
if (playerCorrectSize > correctHight && !transition)
{
platformCollider.isTrigger = false;
}
else if(playerCorrectSize < correctHight - transform.localScale.y && !transition)
{
platformCollider.isTrigger = true;
}
if(Input.GetKeyDown(KeyCode.S) && player.onFloor && !platformCollider.isTrigger)
{
transition = true;
platformCollider.isTrigger = true;
StartCoroutine("waitTime");
}
if (transition) player.canJump = false;
}
IEnumerator waitTime()
{
yield return new WaitForSeconds(0.5f);
transition = false;
player.canJump = true;
}
}
Comment
transform.position gives the position of the object attached to, so thats not the problem, whats your exact issue? whats happening?
youre right, i thought that was the issue, but it wasnt, i have already soved it thank you
Your answer
Follow this Question
Related Questions
Draw call minimizer 1 Answer
Help with script 1 Answer
[C#] Quaternion Rotations with Input.GetAxis problems. 1 Answer
Respawn Point dont work, is because is a prefab? 2 Answers
How to share varibles betweent scripts 4 Answers