#4 gna
ako opraviť kód, aby sa správne objekty umiestnili na bodoch
dakujem
Zdravím
Dlho sa trápim s problémom ako náhodne umiestniť nepriateľov na body,ktoré u mňa tvoria gule? Pri spustení mi objekty umiestni náhodne ale niekedy na nesprávnom mieste,aj tam kde nemám body:
Ďakujem za rady.Tu je kód
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Random = UnityEngine.Random;
public class Randomplace : MonoBehaviour {
public int minNumber =0;
public GameObject[] wayPoints;
public GameObject[] enemys;
Vector3 pos;
private List<int> _validNumbers;
private int number;
private void Awake()
{
_validNumbers = new List<int>();
for (int i = minNumber; i <= wayPoints.Length; i++)
_validNumbers.Add(i);
}
void Start()
{
for (int j=0; j<enemys.Length;j++) {
if(enemys[j].activeInHierarchy) {
enemys[j].SetActive(true);
number = GetRandomNumber();
GameObject waypoint = wayPoints[number];
Vector3 pos= waypoint.transform.position;
enemys[j].transform.position = pos;
Debug.Log( "zomby su na cislach "+wayPoints[number]+"x"+ wayPoints[number].transform.position.x +
"z"+wayPoints[number].transform.position.z+"vola"+enemys[j]);
}
}
}
private void Update()
{
}
private int GetRandomNumber()
{
var nextIndex = Random.Range(0, _validNumbers.Count - 1); //
var result = _validNumbers[nextIndex];
_validNumbers.RemoveAt(nextIndex);
return result;
}
}
#6 MilanL
for (int i = 0; i < vehicle.Length; i++)
{
var dist = Vector3.Distance(transform.position,vehicle[randomInt].transform.position);
Debug.Log("dist"+dist) ;
}
Podarilo sa toto,ale podľa mňa neukazuje aktuálnu vzdialenosť medzi vygenerovanými kockami.
Zdravím
ako sa vypočíta v unity3d,vzdialenosť medzi novými vygenerovanými kockami,keď je gameObject array?
Ďakujem za rady
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class vehicless : MonoBehaviour {
[SerializeField] private GameObject[] vehicle;
[SerializeField] private Transform spawnPos;
[SerializeField] private float minTime;
[SerializeField] private float maxTime;
int randomInt;
// Use this for initialization
void Start () {
StartCoroutine(SpawnVehicle());
}
// Update is called once per frame
void Update () {
}
private IEnumerator SpawnVehicle(){
int i=1;
while(true){
randomInt=Random.Range(0,vehicle.Length);
yield return new WaitForSeconds(Random.Range(minTime,maxTime));
GameObject myPrefabInstance = Instantiate(vehicle[randomInt],spawnPos.position,Quaternion.identity);
var red = myPrefabInstance.gameObject.name; //NAME OBJECT
var namecube = red + i ;
// float dist = Vector3.Distance(transform.position, vehicle[0].transform.position);
// Debug.Log("Name object:"+ namecube) ;
i++;
}
}
}
#4 gna
Nejako sa mi to podarilo podľa príkladu upraviť. A ešte otázka, že keď vojdem do izby, ako sa dá zistiť či daný objekt sa v miestnosti nachádza alebo sa nenachádza napr. pomenujeme modravaza.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class TriggerTest : MonoBehaviour {
private bool guitex=false ;
private bool guitexkuchyna=false;
private bool guitexchodba=false;
private bool guitexbyt=false;
void FixedUpdate()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, 10))
print("There is something in front of the object!");
}
void Start () {
}
// Update is called once per frame
void Update () {
}
// private Color m_oldColor=Color.red;
void OnTriggerEnter(Collider coln)
{
if(coln.tag == "obyvacka2" ){
guitex = true;
guitexkuchyna=false;
Renderer render=GetComponent<Renderer>();
// m_oldColor= render.material.color ;
render.material.color=Color.green;
}else if(coln.tag == "kuchyna"){
Renderer render=GetComponent<Renderer>();
// m_oldColor= render.material.color ;
render.material.color=Color.blue;
guitex = false;
guitexkuchyna=true;
}else if(coln.tag == "chodba"){
guitex = false;
guitexkuchyna=false;
guitexchodba=true;
}else if(coln.tag == "byt"){
guitex = false;
guitexkuchyna=false;
guitexbyt=true;
}
}
void OnTriggerExit(Collider coln)
{ guitex = false;
guitexkuchyna=false;
guitexchodba=false;
guitexbyt=false;
if(coln.tag == "obyvacka2"){
Renderer render=GetComponent<Renderer>();
render.material.color=Color.red;
}
}
private GUIStyle guiStyle = new GUIStyle(); //create a new variable
void OnGUI() {
if (guitex == true )
{
// GUI.contentColor = Color.yellow; //zmena farba textu
guiStyle.normal.textColor = Color.yellow;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do obyvacky",guiStyle);
}else if(guitexkuchyna==true){
guiStyle.normal.textColor = Color.yellow;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do kuchyne",guiStyle);
guitex =false;
}else if( guitexchodba==true){
guitex =false;
guiStyle.normal.textColor = Color.blue;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do chodby",guiStyle);
}else if( guitexbyt==true){
guitex =false;guitexchodba=false;guitexbyt=true;
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do bytu",guiStyle);
}else{
guiStyle.normal.textColor = Color.red;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "", guiStyle);
}
}
}
Zravím
Neviete mi poradiť? Na scéne mám kocku akože miestnosť,ktorá sa volá obývačka a je k nej pridelený Tag:obyvacka. Skript je umiestnený na postavičke,ktorú ovládam a má takýto kód.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class obyvacka : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider col)
{
if(col.tag==("obyvacka")){
Debug.Log("Vosiel som do obyvacky");
}
}
void OnTriggerStay (Collider col)
{
if(col.tag==("obyvacka")){
Debug.Log("Som v obyvacke");
}
}
void OnTriggerExit (Collider col)
{
if(col.tag ==("obyvacka")){
Debug.Log("Vysiel som z obyvacky");
}
}
}
Otázka znie.Ako mám upraviť kód, že keď postava viackrát bude vchádzať do miestnosti, aj vychádzať, aby mi tie funkcie fungovali stále. A nie len vtedy, keď scénu pustím prvýkrát?
ďakujem za rady
#19 Kit
skombinoval som to s mysql,stále mi vypisuje len jeden obrázok a chcem aby mi vypísalo na štyri
SVG súbory mi to upravilo len neviem kde to dať aby vypísalo napr 4 obrázky
<?php ob_start() ;
require __DIR__.'/vendor/html2pdf/autoload.php';
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator("-");
$pdf->SetAuthor('-');
$pdf->SetTitle('Demonstrating pdf with php');
//$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING, array(0, 6, 255), array(0, 64, 128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetMargins(PDF_MARGIN_LEFT-5, PDF_MARGIN_TOP-2, PDF_MARGIN_RIGHT-2);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFont('dejavusans', '', 14, '', true);
$pdf->AddPage();
//$pdf->SetMargins(15, 29, 16,true);
$doc = new \DOMDocument('1.0', 'UTF-8');
$html = <<<EOD
<h1 style="text-align:center">nadpis</h1>
EOD;
$conn = mysqli_connect("localhost", "root", "", "sudoku");
$sql = "SELECT * FROM logickehry limit 4 ";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result))
{
// $img=trim($row['nevyriesene']);
$doc = new \DOMDocument('1.0', 'UTF-8');
$img=trim($row['nevyriesenasvg']);
$doc->load("http://localhost2/word3/logickehry/$img"); //d:/www/word3/34.svg
$symbols = $doc->getElementsByTagName('symbol');
foreach ($symbols as $symbol) {
$id = $symbol->getAttribute('id');
$symbol->removeAttribute('id');
$paths = $symbol->getElementsByTagName('path');
foreach ($paths as $path) {
$path->setAttribute('id', $id);
}
}
$svg= $doc->saveXML();
$G=$pdf->ImageSVG('@'.$svg, $x=215, $y=30, $w='70.00cm', $h='70.00cm',$link='', $align='', $palign='L', $border=1, $fitonpage=false);
$html .= <<<EOD
<img src="d:/www/word3/logickehry/".$svg width="300" height="300">
EOD;
}
$html .= '';
$pdf->writeHTML($html);
//$pdf->writeHTML($html);
// ob_end_clean();
$pdf->Output('test.pdf', 'I');
?>
#19 Kit
$html = 'obsah ';
$pdf->ImageSVG('@' . $svg, $x=15, $y=30, $w='', $h='', $align='', $palign='', $border=1, $fitonpage=false); $pdf->Write(0, $html, '', 0, 'L', true, 0, false, false, 0); $pdf->Output('document.pdf', 'I');
Takto mi to funguje vďaka. A ako by to bolo s viacerými súbormi?
Keby som chcel napríklad ručne vložiť druhý obrázok? Ak by sa obrázky načítali z databázy, tak stačí
do load vložiť názov svg súboru aj s cestami a potom by sa všetky obrázky upravili?
#17 Kit
Dám celý kód
<?php
require __DIR__.'/vendor/html2pdf/autoload.php';
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetSubject('TCPDF priklad');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
//$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
//$pdf->SetFont('dejavusans', '', 10);
$pdf->SetFont('times', 'BI', 20,'', 'false');
// add a page
$pdf->AddPage();
$html = ' obsah
';
$doc = new \DOMDocument('1.0', 'UTF-8');
$doc->load("d:/www/word3/34.svg");
$symbols = $doc->getElementsByTagName('symbol');
foreach ($symbols as $symbol) {
$id = $symbol->getAttribute('id');
$symbol->removeAttribute('id');
$paths = $symbol->getElementsByTagName('path');
foreach ($paths as $path) {
$path->setAttribute('id', $id);
}
}
$svg = $doc->saveXML();
$pdf->writeHTML($svg,true, false, true, false, 'n');
$pdf->Output('example_006.pdf', 'I');
?>>
Odstránil séom aj symbol a pdf je stále prázdny
$doc = new \DOMDocument('1.0', 'UTF-8');
$doc->load("33.svg");
$symbols = $doc->getElementsByTagName('symbol');
foreach ($symbols as $symbol) {
$id = $symbol->getAttribute('id');
$symbol->removeAttribute('id');
$paths = $symbol->getElementsByTagName('path');
foreach ($paths as $path) {
$path->setAttribute('id', $id);
}
}
ECHO $ordernumber= $doc->saveXML();
Už som to dal na pôvodne ale obrázok nie je pdf
#11 Kit
Ja to chcem aby výstup bol v pdf
// add a page
$pdf->AddPage();
//$html = '<img src="34.svg" style="display:block;color:black;width:400;height:400" > ';
//$html = file_get_contents("33.svg");
// output the HTML content +
//$html = utf8_decode($html);
///$pdf->writeHTML($html);
$pdf = new \DOMDocument('1.0', 'UTF-8');
$pdf->load("34.svg");
$symbols =$pdf->getElementsByTagName('symbol');
foreach ($symbols as $symbol) {
$id = $symbol->getAttribute('id');
$symbol->removeAttribute('id');
$paths = $symbol->getElementsByTagName('path');
foreach ($paths as $path) {
$path->setAttribute('id', $id);
}
}
/// $pdf ->saveXML();
$pdf->writeHTML(utf8_encode($html), true, false, true, false, '');
$pdf->Output('example_006.pdf', 'I');
vypisuje chybu
Fatal error: Call to undefined method DOMDocument::writeHTML() in D:\www\word3\15.php on line 51
a môžeš pre viac súborov napísať kód? Symbol tam musí byť aj keď som ručne prepísal id do path.
Viete mi poradiť. Program mi vygeneroval sudoku, vo formáte svg a chcem ju prekonvertovať do súboru pdf a používam plugin TCPDF.Môj problém spočíva v tom, že sudoka sa do pdf nahraje s prázdnou mriežkou bez číslic. Ale keď si sudoku vo formáte svg stiahnem niekde z internetu a skonvertujem do pdf tak je to správne. Len môj obrázok sa nezobrazuje správne - to je mriežka bez číslic. Pripájam aj súbor aj kód.Ďakujem za rady
<?php
require __DIR__.'/vendor/html2pdf/autoload.php';
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetSubject('TCPDF priklad');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
//$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('dejavusans', '', 10);
// add a page
$pdf->AddPage();
$html = '<h1>HTML priklad</h1>
<img src="33.svg" style="display:block;color:black;width:400;height:400" >
';
// output the HTML content
$pdf->writeHTML($html);
$pdf->Output('example_006.pdf', 'I');
?>
A tu je súbor,33.zip,
neviem ako tu mám nahrať súbor,tak som to dal na svoju stránku.
Zdravím
Mám taký problém, že pri generovaní dokumentu,sa mi dokument aj s pravítkom roztiahne na celú šírku,obrázok1,do pokus.ott,používam LibreOffice,lebo podporuje vkladanie svg súboru( obsah je len tak)
tu je kód
<?php
header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header("Content-Disposition: Filename=inzerciatopsk.ott");
?>
<style>
/* default for all pages */
@page {
margin: 2in;
}
/* margin on left page */
@page :left {
margin: 1in;
}
/* margin on right page */
@page :right {
margin: 3in;
}
/* top margin on first page */
@page :first {
margin-top: 5in;
}
h1{
color:green;
}
</style>
<center>
<h1>nadpis</h1>
<h2>podnadpis</h2>
<p>
text text text text text text text
text text text text text text
text text text text text
</p>
<img src="ikony/PDF-icon.png" alt="PDF-icon.png, 5,4kB" title="PDF icon" height="48" width="48">
</center>
a ja by som chcel docieliť, aby sa dokument aj s pravítkom s posuvníkmi dal napr. do formátu A4,viď obrázok 2
ďakujem za radu
Zdravim
mam scrpt jquery,keď kliknem na obrázok tak sa otočí,v druhom php skripte sa uklada ako nový obrázok.Moja otázka znie: Ako uložiť tlačidlo uložiť,že ked kliknem na uložiť abz sa otáčaný obrázok uložil
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://beneposto.pl/jqueryrotate/js/jQueryRotateCompressed.js"></script>
<img src="1.jpg" id="img" width=200/>
<script>
$(document).ready(function(){
var value = 0
$("#img").rotate({
bind:
{
click: function(){
value +=90;
$(this).rotate({ animateTo:value})
}
}
});
});
</script>
php
<?php
$filename = '1.jpg';
$saveto = "uploads/test.jpg";
function RotateImg($filename = '',$angle = 0,$savename = false)
{
$original = imagecreatefromjpeg($filename);
$rotated = imagerotate($original, $angle, 0);
if($savename == false) {
header('Content-Type: image/jpeg');
imagejpeg($rotated);
}
else {
imagejpeg($rotated,$savename);
}
imagedestroy($rotated);
}
RotateImg($filename,90,$saveto);
?>
Ako spočítatť napr. nepriateľov, keď sú traja v jednej miestnosti,dvaja v druhej miestnosti, a v tretia miestnosť je prázdna? Pripajám kód, ktorý mi ukazuje rovnaký počet nepriateľov aj v jednej miestnosti alebo ked vojdem do druhej miestnosti
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class room : MonoBehaviour {
public GameObject[] enemySpawnPoints;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider col) {
if(col.tag==("1") ){
Debug.Log("Vstupil som do miestnosti r1"+enemySpawnPoints.Length);
} else if(col.tag==("2") ){
Debug.Log("Vstupil som do miestnosti r2"+enemySpawnPoints.Length);
}
}
void OnTriggerExit (Collider col) {
if(col.tag==("r1")){
Debug.Log("Vysiel som z mistnosti r1");
}
}
/* void pocetnepriatelov(){
if (enemySpawnPoints.Length >=1)
{
print("Príliš veľa nepriateľov!"+enemySpawnPoints.Length );
}else{
print("miestnost je cista");
}
} */
}
#14 MilanL
tu je spravny kod
function Update () {
distance = Vector3.Distance(enemy.transform.position, player.transform.position);
if( health == 0 ){
animation["Die"].wrapMode = WrapMode.ClampForever;
animation.CrossFade("Die");
}else{
Waipointss();}
}
lebo animacne klipy do funkcie OnCollisionEnter podla mna nepatria a funguje
#9 juraj175
Tu mám kód,že keď bude mať nula akože životov,tak sa mi nechce prehrať animačný klip Die
var health : float = 3;
function Start () {
var animation : Animation;
animator=GetComponent(Animator);
}
function OnCollisionEnter(col:Collision) {
if(col.gameObject.name == "projektile(Clone)" ){
//Destroy(gameObject);
if( health == 0 )
{
//animation.CrossFade("Die");
animation["Die"].wrapMode = WrapMode.ClampForever;
animation.CrossFade("Die");
}else{
GetComponent.<Animation>().Play("Walk");
health--;
Debug.Log("zije"+ health);
}
}
}
Ešte mám otázku. Ako prehrať animačný klip len raz, aby sa stále neopakoval?
GetComponent.<Animation>().Play("Die");
Animačná klip
Add Loop Frame je odškrtnuté
Wrap Mode je once
a typ animácie je Legacy.
A dá sa klip prekopírovať do prefab?
Ako upraviť kód kde sa postava zastaví pri bode 3 napr na 9 sekúnd a po uplinutí času by sa mala pohnúť.
Hodnotu načíta 9s Ale nechce správne odpočitávať timer -= Time.deltaTime; tu je kód
Problematická časť kódu je vyznačená tučným písmom. Ďakujem za rady
#pragma strict
public var wayPoints : Transform[];
var enemy: GameObject;
var player: GameObject;
public var vehicleSpeed : float;
public var curWayPoint : int;
public var turningSpeed : float;
public var doPatrol : boolean = true;
public var target : Vector3;
public var moveDirection : Vector3;
public var Velocity : Vector3;
var minvzdialenostsledovania :float=3;
var moveSpeed :float=3;
private var animator:Animator;
var idleAnimation:AnimationClip;
var walkAnimation:AnimationClip;
var attackAnimation:AnimationClip;
var diem:AnimationClip;
var rb: Rigidbody;
private var nav:NavMeshAgent;
var stop:boolean= true;
public var timer:float;
function Start()
{
var animation : Animation;
animator=GetComponent(Animator);
rb = GetComponent.<Rigidbody>();
}
function Update()
{
var distance = Vector3.Distance(enemy.transform.position, player.transform.position);
Debug.Log(distance);
if(distance>=3 && distance<=4 ){
Debug.Log("pozoruje"+distance);
lookAtPlayer();
rb.velocity=Vector3.zero;
GetComponent.<Animation>().Play("Idle_02");
GetComponent.<Animation>().Stop("Walk");
}else if(distance>4){
Debug.Log("strazi objekt"+distance +"bod"+curWayPoint);
/*tu sa otoci*/
rigidbody.rotation = Quaternion.Slerp(enemy.transform.rotation,Quaternion.LookRotation(-moveDirection),turningSpeed * Time.deltaTime);
Waipointss();
}
if(distance<=3){
GetComponent.<Animation>().Play("Walk");
GetComponent.<Animation>().Stop("Idle_02");
Debug.Log("prenasleduje"+distance);
enemy.transform.position += enemy.transform.forward * 1 * Time.deltaTime;
lookAtPlayer();
}else{
//Waipointss();
}
}
function Waipointss(){
if(curWayPoint < wayPoints.Length)
{
target = wayPoints[curWayPoint].position;
moveDirection = target - enemy.transform.position;
Velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
curWayPoint++;
}
else
{
Velocity = moveDirection.normalized * vehicleSpeed;
}
}
else
{
if(doPatrol)
{
curWayPoint = 0;
}
else
{
Velocity = Vector3.zero;
}
}
rigidbody.velocity = Velocity;
/*tu sa otoci*/
rigidbody.rotation = Quaternion.Slerp(enemy.transform.rotation,Quaternion.LookRotation(moveDirection),turningSpeed * Time.deltaTime);
if(curWayPoint==3){
timer = 9.0;
if (timer <= 0) {
timer -= Time.deltaTime;
//We only need to update the text if the score changed.
GetComponent.<Animation>().Play("Walk");
//Reset the timer to 0.
timer = 0.0;
}else{
Debug.Log("timer"+timer);
GetComponent.<Animation>().Stop("Walk");
GetComponent.<Animation>().Play("Idle_02");
rb.velocity=Vector3.zero;
Debug.Log("cas"+timer);
}
}
GetComponent.<Animation>().Play("Walk");
}
function lookAtPlayer(){
var relativePos = player.transform.position-enemy.transform.position ;
var rotation = Quaternion.LookRotation(relativePos);
enemy.transform.rotation = rotation;
}
#14 peter
Mohol by si mi upraviť ten kód, všetky podkategórie sa uložili k hlavnej ale k podkategóriam neviem správne priradit parent_id
<?include_once "connect.php";set_time_limit(0);
ini_set('memory_limit', '2000M');?>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<?php
$xml=simplexml_load_file("https://dedra.blob.core.windows.net/cms/xmlexport/cs_xml_export.xml?ppk=285765") or die("Error: Cannot create object");
$already_used = array();
$vsetkykat = 0;
foreach($xml->children() as $category) {
$catname = $category->kategorie;
$catname = strip_tags($catname);
$tovar = $category->text1;
$product_id = $category->product_id;
$kategoriep = explode("/", $catname);
$kategorieppp =count($kategoriep);
$output[]=$kategoriep[0];
for($i=0;$i<count($kategoriep);$i++){
foreach($kategoriep as $key=>$value){ $id=mysql_insert_id()+1;
if(!in_array($kategoriep[$i],$output)){
if(!in_array($value,$output)){
$kategoriep[0];
$output[]=$kategoriep[$i];
echo "Hlavnakat" ; echo $kategoriep[0];
echo $kategoriep[$i];
echo $product_id;
echo $tovar;
echo "<br>";
if($kategoriep[0]){//ulozili sa hlavne kategorie
$sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[0]'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count > 0) {
print " Kategoria uz existuje";
}
else {
$sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[0]'";
$sql="INSERT INTO kategorie(name,parent_id,patrikhlavnejkatid)
VALUES('$kategoriep[0]','0','$id')";
$result=mysql_query($sql);
}
}if($kategoriep[$i]){//ulozili sa hlavne kategorie
$sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[$i]'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count > 0) {
print " Kategoria uz existuje";
}
else {
echo "juraj"; echo $kategoriep[0];
// $sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[$i]'";
$sql = "SELECT id,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[0]'";
$result = mysql_query($sql);
WHILE(LIST($id,$patrikhlavnejkatid) = mysql_fetch_row($result)) {
//$resulti = mysql_query("INSERT INTO kategorie (name,parent_id,patrikhlavnejkatid) VALUES ('$kategoriep[$i]','55','$patrikhlavnejkatid')");
$sqlf="INSERT INTO kategorie(name,parent_id,patrikhlavnejkatid)
VALUES('$kategoriep[$i]','$id','$patrikhlavnejkatid')";
$resultf=mysql_query($sqlf);
echo $value;echo"fff";
}
}
}
}
}
}
} $vsetkykat++;
}
if($vsetkykat==$vsetkykat){
echo "koniec kategorii,nvlozia sa tovary";
}
?>
</body>
</html>
#10 peter
Hlavné kategórie sa uložili do tabuľky mysql,ako docieliť, aby sa uložili podkategórie k hlavným kategóriám
hlavná kategória napr Drogerie
a pod drogériu by sa uložili
Praní
Vychytávky
Kosmetika
Péče o tělo
Mýdla a pěny na ruce
<?include_once "connect.php";set_time_limit(0);
ini_set('memory_limit', '2000M');?>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<?php
$xml=simplexml_load_file("https://dedra.blob.core.windows.net/cms/xmlexport/cs_xml_export.xml?ppk=285765") or die("Error: Cannot create object");
$already_used = array();
foreach($xml->children() as $category) {
$catname = $category->kategorie;
$catname = strip_tags($catname);
$tovar = $category->text1;
$product_id = $category->product_id;
$kategoriep = explode("/", $catname);
$kategorieppp =count($kategoriep);
$output[]=$kategoriep[0];
for($i=0;$i<count($kategoriep);$i++){
foreach($kategoriep as $key=>$value){
if(!in_array($kategoriep[$i],$output)){
if(!in_array($value,$output)){
echo $kategoriep[0];
print $output[]=$kategoriep[$i];
echo $product_id;
echo $tovar;
echo "<br>";
if($kategoriep[0]){//ulozili sa hlavne kategorie
echo $sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[0]'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count > 0) {
print " Kategoria uz existuje";
}
else {
$sql = "SELECT id,name,patrikhlavnejkatid from kategorie WHERE name = '$kategoriep[0]'";
if($kategoriep[0]){
$result = mysql_query("INSERT INTO kategorie (name,parent_id) VALUES ('$kategoriep[0]','0')");
}
}
}
}
}
}
}
}
?>
#6 peter
Zdravím tu je celý skript a ako to hodiť do mysql.Neviem prečo tu sa spomína excel ,ked je to v xml subore
<?include_once "connect.php";set_time_limit(0);
ini_set('memory_limit', '2000M');?>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<?php
$xml=simplexml_load_file("https://dedra.blob.core.windows.net/cms/xmlexport/cs_xml_export.xml?ppk=285765") or die("Error: Cannot create object");
$already_used = array();
foreach($xml->children() as $category) {
$catname = $category->kategorie;
$tovar = $category->text1;
$product_id = $category->product_id;
$kategoriep = explode("/", $catname);
$kategorieppp =count($kategoriep);
$output[]=$kategoriep[0];
for($i=0;$i<count($kategoriep);$i++){
foreach($kategoriep as $key=>$value){
if(!in_array($kategoriep[$i],$output)){
if(!in_array($value,$output)){
print $output[]=$kategoriep[$i];
echo $product_id;
echo $tovar;
echo "<br>";
}
}
} } }
?>
</body>
</html>
#2 peter
napr z tejto adresy
https://dedra.blob.core.windows.net/cms/xmlexport/cs_xml_export.xml?ppk=285765
export tieto položky do php a mysql, nejaký jednoduchý skript
aby sa kategorie s podkategóriami uložili do jednej tabulky ,tovary do druhej tabulky k prislušným kategóriám a do tretej tabuľky s obrázky
Zdravím ako z reťazca vytvoriť hlavné kategórie a podkategórie,ktoré sa načítavajú z xml súboru v tvare
<product product_id="1" >
<kategorie>Drogerie / Domov / Autokosmetika</kategorie>
</product>
<product product_id="2" >
<kategorie>Drogerie / Praní / Prací prostředky / Speciály</kategorie>
</product>
a chcem dostať
hlavná kategória
Drogerie
Kuchyně
Mytí nádobí
Ruční mytí nádobí
a tu je php kód ako som sa dostal ďaleko
<?include_once "connect.php";set_time_limit(0);
ini_set('memory_limit', '2000M');?>
<?php
$xml=simplexml_load_file("....") or die("Error: Cannot create object");
$already_used = array();
foreach($xml->children() as $category) {
$catname = $category->kategorie;
$kategoriep = explode("/", $catname);
$kategorieppp =count($kategoriep);
$output[]=$kategoriep[0];
for($i=0;$i<count($kategoriep);$i++){
if(!in_array($kategoriep[$i],$output)){
print $output[]=$kategoriep[$i];echo "<br>";
}
}
}
?>
Zdravím
Ako z databázy mysql vypísať podobné záznamy?
Používam tento príkaz
$sqle = " SELECT id,name FROM title WHERE MATCH(name) AGAINST('$search' )";
Ak do inputu search zadám slovo Šmolkovia tak mi vypíše tieto záznamy
Purpuroví Šmolkovia - Šmolkovia
Šmolkovia
ale záznam Epizódy Šmolkov už nevypíše
ďakujem za rady
#7 MilanL -- domova
Premennú timer definujem takto
var timer : float ;
if(curindex==2 ){
timer -= Time.deltaTime;
//timer -= Time.deltaTime;
transform.Translate(Vector3.zero);
if(timer <= 0){
timer = 0.0;
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
}else if (curindex==3 ){
if(timer<=0){
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
else{
timer -= Time.deltaTime;
transform.Translate(Vector3.zero);
}
}
else{
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
Ak dojde kocka k bodu 2 tak cas počíta správne k nule, ale ak dojde k bodu 3 tak sa nic nedej.Tmten predosli kod odpocitava cas ale nedôjde k nule.Mam dať tu celý kód?
#5 MilanL
Upravil som to takto,ale keď príde k bodu 3 tak sekundy sa nepripočitaj k timer
if(curindex==2 ){
timer -= Time.deltaTime;
//timer -= Time.deltaTime;
transform.Translate(Vector3.zero);
if(timer <= 0){
timer = 0.0;
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
}else if (curindex==3 ){
if(timer<=0){
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
else{
timer -= Time.deltaTime;
transform.Translate(Vector3.zero);
}
}
else{
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
Zdravím
vyskúšal som aj
var timer : float;
aj takýto zápis
var timer : float = 2;
a nepočíta to k nule
if(curindex==2 ){
timer = 2.0 ;
timer -= Time.deltaTime;
transform.Translate(Vector3.zero);
if(timer <= 0){
timer = 0;
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
}
Zdravím
chcem sa spýtať či neviete poradiť mám v UNITY3D javascript nadefinovanú premennú
var timer : float;
Chcem docieliť,keď kocka dojde k bodu 2,tak sa zastaví napr na 2 sekundy,potom dojde k bodu 3 tam sa tiež zastaví na 2s a tak ďalej
Tu je kód
if(curindex==2){
transform.Translate(Vector3.zero);
timer -= Time.deltaTime;transform.Translate(Vector3.zero);
if(timer <= 0){
timer = 0;
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
}else if (curindex==3){curindex=3;
transform.Translate(Vector3.zero);
timer=2;
timer -= Time.deltaTime;
Debug.Log(timer);
transform.Translate(Vector3.zero);
if(timer <= 0){
timer = 0;
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
}else{
transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
}
Problém je taký,že keď príde k bodu 3
curindex==3 tak
timer=2; timer -= Time.deltaTime; tak to správne nepočíta funkcia sekundy
Vdaka
Ako spočítať podkategórie,ktoré patria k hlavnej kategóriam
<?php
function get_menu($data, $parent_id = 0) {
static $i = 1;
$tab = str_repeat("\t\t", $i);
if (isset($data[$parent_id])) {
$html = "\n$tab<ul>";
$i++;
foreach ($data[$parent_id] as $v) {
$child = get_menu($data, $v->cat_id);
$html .= "\n\t$tab<li>";
$id = $v->cat_id;
$title = $v->cat_name;
$level= $v->level;
$j="jjj";
$html .= '<a href="'.$id.'">'.$title.'-'.$level.'-'.$j.'</a>';
// $html .= '<a href="'.$id.'">'.$title.'</a>';
if ($child) {
$i--;
$html .= $child;
$html .= "\n\t$tab";
}
$html .= '</li>';
}
$html .= "\n$tab</ul>";
return $html;
} else {
return false;
}
}
$result = mysql_query("SELECT * FROM categories ORDER BY cat_name asc");
$count=mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
$data[$row->parent_id][] = $row;
}
$menu = get_menu($data);
?>
<div id="myjquerymenu" class="jquerycssmenu">
<?php echo $menu; ?>
</div>
Zdravím
v xml súbore mam napr elementzy id 1,id 2 ,id 3
ak v súbore zmazžem napr id3 ako to urobiť v php aby prvok v id3 sa zmazal aj v mysql?Skusal som aj detle no in ale to tak nefunguje ako som si predstavoval
dakujem za rad
#8 juraj175
niečo som sa snažil a ako upraviť, aby nevznikali vedľajšie bunky?
<style>
.SizeChooser table {
border-collapse: separate;
border-spacing: 3px;
}
.SizeChooser td {
cursor: pointer;
border: 1px #ccc solid;
height: 10px;
min-width: 10px;
line-height: 10px;
}
.SizeChooser-selected {
border: 1px #333 solid !important;
}
.SizeChooser-hover {
background-color: #DEF;
}
</style>
<script src="http://inzerciatop.sk/js2/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script>
<script>
$(document).ready(function(){
var columns;
var rows;
$('td').hover(function() {
var n = $(this).index();
var m = $(this).parent('tr').index();
$('td').removeClass('SizeChooser-hover');
$('tr').each(function(y) {
$(this).find('td').each(function(x) {
if (x <= n && y <= m) {
$(this).addClass('SizeChooser-hover');
document.getElementById("stlpce").innerHTML = y+1;
document.getElementById("riadky").innerHTML = x+1;
}
})
})
}).click(function(){
var table = document.getElementById ("myTable");
columns = $(this).index()+1;
rows = $(this).parent('tr').index()+1;
// alert( table.rows[rows].cells[columns].innerHTML);
$('td').removeClass('SizeChooser-selected');
$('td.SizeChooser-hover').addClass('SizeChooser-selected');
});
$('#merge').click(function() {
var myTable = document.getElementById('myTable');
var table = document.getElementById('myTable');
var td = document.querySelector('td');
td.setAttribute('rowspan', rows);
td.setAttribute('colspan',columns);
spolu=rows*columns;
});
});
</script>
</style>
<span id="riadky"></span> x <span id="stlpce"></span>tabulka<br>
<button type="button" id="merge">merge</button>
<div class="table_size_chooser">
<div class="SizeChooser">
<table id=myTable width=500>
<tbody>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr >
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
<tr>
<td class="SizeChooser-selected SizeChooser-hover">d </td>
<td class="SizeChooser-selected SizeChooser-hover"> d</td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover">v </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> v</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-selected SizeChooser-hover"> b</td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover">b </td>
<td class="SizeChooser-selected SizeChooser-hover"> zzq</td>
<td class="SizeChooser-hover SizeChooser-selected"> juraj</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
<td class="SizeChooser-hover SizeChooser-selected"> b</td>
</tr>
</tbody>
</table>
</div>
</div>
#4 peter
Google som prelistoval dost vela,ale aj tak to nie je ono ako si to predstavujem.
Ja si to predstavujem asi tak, že keď si v tabulke vyberiem napr. štyri stlpce s desiatimy riadkami a kliknem na tlačidlo, ktoré je umiestnené mimo tabuľky, aby sa tie vybraté bunky zlúčili
ďakujem
#2 peter
$("#merge").click(function () {
//code here
/*td.setAttribute('rowspan', rows);
td.setAttribute('colspan',columns);*/
//alert("code here for rowspan and colspan cells")
tr = y2; // z td se na to dostanes pres td.parentNode
td = tr.getElementsByTagNames('TD');
td[0].innerHTML += td[1].innerHTML; // spojis obsah td[0] a td[1]
td[0].colspan = (td[0].colspan ? td[0].colspan*1 : 1) + (td[1].colspan ? td[1].colspan*1 : 1); // nastavis colspan
tr.removeChild(td[1]); // odstranis td[1]
});
keď som ten kód zkopíroval do tlacidla merge tak mi to nič nerobí.Môžeš mi to upraviť, aby po vybratí buniek
sa zlúčili do colspan alebo rowspan? Nejako mi to nefunguje dakujem
Zdravím ako zlúčiť bunky v tabuľke, keď ich vyberiem myšou v
jquery
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <style> table td { border:1px solid #ddd; height:30px; -moz-user-select:none; -webkit-user-select:none; user-select:none; } .selected { background:#69c; } table { width:100%; border-collapse:collapse; } </style> <script> window.onload = function () { $('td').mousedown(function () { $(this).closest('table').find('td').removeClass('selected'); start = { x: this.cellIndex, y: this.parentNode.rowIndex } $(this).closest('table').find('td').mouseover(function () { x1 = Math.min(start.x, this.cellIndex); y1 = Math.min(start.y, this.parentNode.rowIndex); x2 = Math.max(start.x, this.cellIndex); y2 = Math.max(start.y, this.parentNode.rowIndex); $(this).closest('table').find('td').each(function () { x = this.cellIndex; y = this.parentNode.rowIndex; if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { $(this).addClass('selected'); } else { $(this).removeClass('selected'); } }); }); self = this; $(document).mouseup(function () { $(self).closest('table').find('td').unbind('mouseover'); $(document).unbind('mouseup'); }); }) $("#merge").click(function () { //code here /*td.setAttribute('rowspan', rows); td.setAttribute('colspan',columns);*/ alert("code here for rowspan and colspan cells") }); } </script> <input type="button" id="merge" value="Merge Cells"> <table align="left" height="200" border="1" bordercolor="0" cellpadding="2" cellspacing="2" width="200"> <tbody> <tr> <td height="20" width="40"> </td> <td height="20" width="40"> </td> <td height="20" width="40"></td> <td height="20" width="40"> </td> </tr> <tr> <td height="20" width="40"></td> <td height="20" width="40"></td> <td height="20" width="40"></td> <td height="20" width="40"></td> </tr> <tr> <td height="20" width="40"></td> <td height="20" width="40"></td> <td height="20" width="40"> </td><td height="20" width="40"></td> </tr> <tr> <td height="20" width="40"></td> <td height="20" width="40"> </td><td height="20" width="40"></td> <td height="20" width="40"></td> </tr> </tbody> </table>